Codeforces Round #436 (Div. 2)
来源:互联网 发布:禁止域名转出万网 编辑:程序博客网 时间:2024/06/06 20:30
题目:http://codeforces.com/contest/864
A.Fair Game
题意:两人将卡片拿光,且数量相等
The game is considered fair if Petya and Vasya can take all n cards, and the number of cards each player gets is the same.
代码:
#include<bits/stdc++.h>using namespace std;map<int,int> mp;map<int,int>::iterator one,two;int main(){ int n,x; cin >> n; for(int i = 0;i < n;i++) cin >> x,mp[x]++; one = mp.begin(); two = ++mp.begin(); if(mp.size() == 2 && one->second == two->second) printf("YES\n%d %d\n",one->first,two->first); else printf("NO\n"); return 0;}
B.Polycarp and Letters
题意:pos为小写字母的位置,且字母中间是小写字母,即求最长的连续不同字母小写字母数
代码:
#include<bits/stdc++.h>using namespace std;char s[205];map<int,int> mp;int main(){ int n,x; cin >> n; cin >> s; int maxn = 0,tmp = 0; for(int i = 0;i < n;i++) { if(s[i] >= 'a' && s[i] <= 'z') { if(mp[s[i]] == 0) tmp++; mp[s[i]]++; } else { maxn = max(maxn,tmp); tmp = 0; mp.clear(); } } if(tmp) maxn = max(maxn,tmp); cout << maxn << "\n"; return 0;}
C.Bus
题意:一趟来回定义为从0到a,或者从a到0,f位置有一个加油站,让你跑k次来回,求加油数(油箱容量b)
代码:
#include<bits/stdc++.h>using namespace std;int main(){ int a,b,f,k; cin >> a >> b >> f >> k; int st,ed; int cur = b,ans = 0; for(int i = 1;i <= k;i++) { if(i&1) st = 0,ed = a; else st = a,ed = 0; if(cur < abs(f-st)) cur = b,ans++; if(cur < abs(f-st)) return 0 * printf("-1\n"); cur -= abs(f-st); if(i != k)//不是最后一趟 { if(cur < abs(ed-f)*2) cur = b,ans++; if(cur < abs(ed-f)*2) return 0 * printf("-1\n"); cur -= abs(ed-f); } else { if(cur < abs(ed-f)) cur = b,ans++; if(cur < abs(ed-f)) return 0 * printf("-1\n"); cur -= abs(ed-f); } } cout << ans << "\n"; return 0;}
D.Make a Permutation!
题意:给你一个数列(1~n),你可以操作一个数,最后使得成为1~n的全排列,求最小操作数
代码:
#include<bits/stdc++.h>using namespace std;const int N = 200005;int a[N],cnt[N],v[N],vis[N];int main(){ ios_base::sync_with_stdio(0);cin.tie(0); int n; cin >> n; for(int i = 1;i <= n;i++) cin >> a[i],cnt[a[i]]++; int num = 0; for(int i = 1;i <= n;i++) if(cnt[i] == 0) v[++num] = i; int p = 1; for(int i = 1;i <= n;i++) { if(cnt[a[i]] > 1) { if(v[p] < a[i] || vis[a[i]]) cnt[a[i]]--,a[i] = v[p],p++; else vis[a[i]] = 1; } } cout<<num<<"\n"; cout<<a[1]; for(int i = 2;i <= n;i++) cout<<" "<<a[i]; cout<<"\n"; return 0;}
E.Fire
题意:失火了,有n个文件,保存文件需要t时间,文件会在d时间被摧毁,求最多能得到最大价值的文件
思路:dp……
阅读全文
0 0
- Codeforces Round #436 (Div. 2)
- Codeforces Round #436 (Div. 2)
- [Codeforces Round #436](Div. 2)
- Codeforces Round #436 (Div. 2)
- Codeforces Round #436 (Div. 2)
- Codeforces Round #436 (Div. 2)
- [Codeforces Round #436 (Div. 2)]
- Codeforces Round #436 (Div. 2)
- Codeforces Round #436 (Div. 2)
- Codeforces Round #436 (Div. 2)
- Codeforces Round #436 (Div. 2)
- Codeforces Round #436 (Div. 2) E. Fire
- Codeforces Round #436 (Div. 2) (题解)
- Codeforces Round #436 (Div. 2)E.Fire
- Codeforces Round #436 (Div. 2) C. Bus
- Codeforces Round #436 (Div. 2) Fire
- Codeforces Round #436 (Div. 2)Bus
- Codeforces Round #436 (Div. 2) 解题报告
- HDU 5517 2015沈阳现场赛(二维树状数组)
- Codeforces Round #436 (Div. 2) C. Bus(模拟)
- 关于同步和异步,阻塞和非阻塞,BIO和NIO知识点
- 协议
- Codefest 17 C. Helga Hufflepuff's Cup(树形DP)
- Codeforces Round #436 (Div. 2)
- loadrunner Web_类函数之web_report_data_point()
- 1.NoSQL与MongoDB简介
- WebService学习笔记
- Java——多态,引用数据类型强转,组合模式
- 2.MongoDB基本操作
- java代理模式
- angularjs速成学习个人理解_3表达式filter过滤器的使用
- 菜鸟前端日记1(HTML+CSS )