Codeforces Round #366 (Div. 2) 题解
来源:互联网 发布:淘宝客怎么关闭 编辑:程序博客网 时间:2024/05/18 14:12
题目链接: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;elsecout << 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;elsecout << 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;}
1 0
- Codeforces Round #366 (Div. 2)题解报告
- Codeforces Round #366 (Div. 2) 题解
- 【codeforces】Codeforces Round #276 (Div. 2) 题解
- 【codeforces】Codeforces Round #277 (Div. 2) 题解
- 【codeforces】Codeforces Round #279 (Div. 2) 题解
- 【codeforces】Codeforces Round #283 (Div. 2) 【题解】
- 【codeforces】Codeforces Round #291 (Div. 2) 题解
- Codeforces Round #131 (Div. 2) 完整题解
- Codeforces Round #135 (Div. 2)题解
- Codeforces Round #192 (Div. 2) 题解报告
- Codeforces Round #194 (Div. 2) 题解
- Codeforces Round #216 (Div. 2)部分题解
- Codeforces Round #226 (Div. 2) 题解
- Codeforces Round #177 (Div. 2) 题解
- Codeforces Round #FF (Div. 2) 题解
- Codeforces Round #256 (Div. 2) 题解
- Codeforces Round #257 (Div. 2) 题解
- Codeforces Round #259 (Div. 2) 题解
- HDU1024——Max Sum Plus Plus(dp)
- .tpl模板
- 像360悬浮窗那样,用WindowManager实现炫酷的悬浮迷你音乐盒(下)
- jquery ajax 从后台获取数据到界面
- 统计一串字符串中不同的词的个数
- Codeforces Round #366 (Div. 2) 题解
- TREC2016 Real-time Summarization 总结
- JavaScript-cookie
- C语言中的冒泡排序(2种)和选择排序
- Android WebView 与js交互初探
- javascript全文检索工具
- Number of Islands
- 查找 window 下边的所有ScrollView
- 码神Android培训01