题目链接:http://codeforces.com/contest/705
A.思路:找规律。仔细看一下样例,大概就知道规律了。先输出"I hate ",然后将计数减一,再每次输出"that ",然后交替输出"I love "、"I hate ",直到计数结束,最后再输出"it"。详见代码。
附上AC代码:
#include <bits/stdc++.h>
using namespace std;
const char s1[] = "I hate ";
const char s2[] = "I love ";
int n;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n;
cout << s1;
--n;
for (int i=0; i<n; ++i){
cout << "that ";
if ((i&1) == 0)
cout << s2;
else
cout << s1;
}
cout << "it" << endl;
return 0;
}
B.思路:简单的博弈。每次都要拆环成两段,而且每段必须要有至少一个点,不能拆就输了。所以只需要求和判断一下奇偶即可。详见代码。
附上AC代码:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n;
ll sum = 0;
int num;
for (int i=0; i<n; ++i){
cin >> num;
sum += num-1;
if (sum%2 == 0)
cout << 2 << endl;
else
cout << 1 << endl;
}
return 0;
}
C.思路:就是模拟一下就好了,但肯定不能太暴力了,稍微有技巧一下就可以了。用vector数组存储每个应用的所有信息编号,set存储未读消息,一个计数器记录是第几条消息,然后开始模拟,代码较简单,会用STL就很容易,所以不详述。详见代码。
附上AC代码:
#include <bits/stdc++.h>
using namespace std;
const int maxn = 300005;
vector<int> v[maxn];
set<int> s;
set<int>::iterator it;
int n, q;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> q;
int cnt=0, a, b;
while (q--){
cin >> a >> b;
if (1 == a){
v[b].push_back(++cnt);
s.insert(cnt);
}
else if (2 == a){
for (int i=0; i<v[b].size(); ++i){
int id = v[b][i];
s.erase(id);
}
v[b].clear();
}
else{
while (!s.empty()){
if (*s.begin() > b)
break;
s.erase(*s.begin());
}
}
cout << s.size() << endl;
}
return 0;
}