B3812 std::string 题解
Hack 的方法:
负数!
炸数组(越界)!
超时!
要领:
看数据范围!
进入正题:
Problem :
你需要 Hack 的 Code:
#include <iostream>
using namespace std;
int main() {
int n;
string ans, base = "HelloLuogu";
cin >> n;
while (n--) ans = ans + base;
cout << ans << endl;
}(属于用不正常的方法做一个入门题)
非常的明显,当 极大的时候,此程序会超时(炸掉),在本地 Dev-C++ 一试, 秒了,还是没有响应,所以 Problem 的代码大家应该知道了吧~~~
Problem :
你需要 Hack 的 Code:
#include <vector>
#include <iostream>
#include <algorithm>
int T;
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int n;
std::cin >> n;
std::vector<int> a(n + 1), pre(n + 2), post(n + 2);
for (int i = 1; i <= n; ++i) std::cin >> a[i];
pre[1] = a[1];
for (int i = 2; i <= n; ++i) pre[i] = pre[i - 1] & a[i];
post[n] = a[n];
for (int i = n - 1; i; --i) post[i] = post[i + 1] & a[i];
int ans = 1;
for (int i = 1; i < n; ++i) if (pre[i] + post[i + 1] == pre[n]) {
++ans;
}
std::cout << ans << '\n';
}(稍微有点难)
Problem 想要炸数组是不可能滴,因为有 vector,炸不了啊~~~
但我们发现第二个循环,是从 的,所以只要输入一个 程序就会 WA 掉(即 Wrong Answer)
代码
(你们最喜欢的部分来喽~)
#include<bits/stdc++.h>
using namespace std;
int main(){
int x;
cin>>x;
if(x==1) cout<<100000;
else if(x==2){
cout<<6<<endl;
cout<<114514<<" "<<0<<" "<<22332<<" "<<1000000000<<" "<<98898<<" "<<65536;
}else{//this code will not be executed
cout<<"I AK IOI!!!!!!";
}
return 0;
}