Codeforces Round #303 (Div. 2) A B C D
来源:互联网 发布:帝国cms仿砍柴网 编辑:程序博客网 时间:2024/06/05 11:23
题目链接:http://codeforces.com/contest/545
A:水
代码:
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <string>#include <queue>#include <set>using namespace std;int n, ans[110],tmp[21000],num;int p[110][110];int main(){ while (cin >> n) { set<int> q; q.clear(); num = 0; for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) { scanf("%d", &p[i][j]); if (p[i][j] == -1) { q.insert(i); q.insert(j); } else if (p[i][j] == 0) { q.insert(i); q.insert(j); } else if (p[i][j] == 1) { tmp[num++] = i; q.insert(j); } else if (p[i][j] == 2) { tmp[num++] = j; q.insert(i); } else if (p[i][j] == 3) { tmp[num++] = i; tmp[num++] = j; } } for (int i = 0; i < num; i++) q.erase(tmp[i]); set<int> ::iterator it; cout << q.size() << endl; for (it = q.begin(); it != q.end(); it++) cout << *it << " "; cout << endl; } return 0;}
B: s ,t 字符不同的位置 ,奇数用s 偶数t,其他位置随意。
代码:
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <string>#include <queue>#include <set>using namespace std;char s[100010],t[100010];int ans[100010];int main(){ while (cin >> s >> t) { int len = strlen(s); int tmp = 0; memset(ans,0,sizeof(ans)); int num = 0; for (int i = 0; i < len; i++) { if (s[i] != t[i]) { tmp++; ans[i] = -1; } } if (tmp % 2 == 1) puts("impossible"); else { for (int i = 0; i < len; i++) { if (ans[i] == -1) { num++; if (num % 2 == 0) printf("%d", (s[i] - '0')); else printf("%d", (t[i] - '0')); } else printf("%d", (s[i] - '0')); } printf("\n"); } } return 0;}
C: 贪心直接搞
代码:
#include <vector>#include <string>#include <algorithm>#include <iostream>#include <stdio.h>using namespace std;const int MAXN=100010;int n;int dp[10010];struct node{ int x; int y; int left,right;}p[MAXN];bool cmp(node a,node b){ return a.x < b.x;}int main(){ while (cin>>n) { for(int i=1;i<=n;i++) { cin>>p[i].x>>p[i].y; p[i].left = p[i].x - p[i].y; p[i].right = p[i].x + p[i].y; } sort(p+1,p+1+n,cmp); int ans=0; int pos = -2000000000; for(int i=1;i<=n;i++) { if (p[i].x - p[i].y > pos) { pos = p[i].x; ans++; } else if (i == n || p[i].x + p[i].y < p[i+1].x) { pos = p[i].x + p[i].y; ans++; } else pos = p[i].x; } cout<<ans<<endl; } return 0;}
D: 排序直接搞 ,不满足条件直接不选。
代码:
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <string>#include <queue>#include <set>using namespace std;int n;int p[100010];int main(){ while (cin >> n) { for (int i = 1; i <= n; i++) cin >> p[i]; sort(p + 1, p + 1 + n); long long tot = p[1]; int ans = 1; for (int i = 2; i <= n; i++) { if (p[i] >= tot) { ans++; tot += p[i]; } } printf("%d\n",ans); } return 0;}
0 0
- Codeforces Round #303 (Div. 2) A B C D
- Codeforces Round #303 (Div. 2)(A,B,C,D)
- Codeforces Round #179 (Div. 2)A、B、C、D
- Codeforces Round #186 (Div. 2)A、B、C、D、E
- Codeforces Round #202 (Div. 2) (A、B、C、D)
- Codeforces Round #211 (Div. 2)(A,B,C,D)
- Codeforces Round #220 (Div. 2)(A,B,C,D)
- Codeforces Round #231 (Div. 2)A, B, C, D
- Codeforces Round #258 (Div. 2)-(A,B,C,D,E)
- Codeforces Round #246 (Div. 2) A,B,C,D
- Codeforces Round #261 (Div. 2) A,B,C,D,E
- Codeforces Round #259 (Div. 2) A/B/C/D
- Codeforces Round #257 (Div. 2) A/B/C/D
- Codeforces Round #256 (Div. 2) A/B/C/D
- Codeforces Round #262 (Div. 2)-A,B,C,D
- Codeforces Round #263 (Div. 2) A,B,C,D,E
- Codeforces Round #264 (Div. 2) A,B,C,D,E
- Codeforces Round #276 (Div. 2) A B C D
- bitmapfactory.options使用总结
- [Javascript] 爬虫 模拟新浪微博登陆
- 新装xampp无法启动appache的解决办法
- 深度理解链式前向星
- Problem A: [NOIP2005]青蛙过河 T2
- Codeforces Round #303 (Div. 2) A B C D
- Mogon - 简单操作
- nginx的搭建详解
- Redis集群方案,Codis安装
- Sqlite3基础
- javac命令和jar命令
- 返回List 形式的数据
- login_pwd.xml
- leetcode--Pascal's Triangle II