Codeforces Round #401 (Div. 2) (solve 4 of 5)
来源:互联网 发布:办公软件考试系统 编辑:程序博客网 时间:2024/06/15 14:40
A - Shell Game【暴力】
题意:
1.有三个坑,小球在其中一个坑。
2.执行
3.奇数次
4.数据范围:
思路:
1.周期为
2.暴力枚举坑的位置
代码:
#include <bits/stdc++.h>using namespace std;typedef long long LL;typedef pair<int,int> pii;int n, x;bool judge(int i) { int a[3]; n %= 30; memset(a, 0, sizeof(a)); a[i] = 1; for(int i = 1; i <= n; i++) { if(i % 2 == 0) swap(a[1], a[2]); else swap(a[0], a[1]); } if(a[x] == 1) return true; return false;}int main() { scanf("%d%d", &n, &x); for(int i = 0; i < 3; i++) { if(judge(i)) { cout << i << endl; return 0; } } return 0;}
B.Game of Credit Cards【贪心】
题意:
1.这题的作者估计也是希望夏洛克和莫里亚蒂搞基的。
2.给你两串长度为
3.比对每一位,数字小的要被弹脑壳。
4.调整数字顺序。求莫里亚蒂最少被弹次数,和夏洛克最多被弹次数。
(PS.因为小莫比较受,所以应该少被弹)
思路:
1.问题一的贪心策略:从小到大sort两人的数字。每一次攻夏拿出一个当前最小数字,小莫应该拿出尽可能小的不被弹的数字。
2.问题二的贪心策略:从大到小sort两人的数字。每一次小莫拿出一个当前最大数字,攻夏应该拿出尽可能大的被弹的数字。
代码:
#include <bits/stdc++.h>using namespace std;typedef long long LL;typedef pair<int,int> pii;int a[1010], b[1010];bool cmp(const int &a, const int &b) { return a > b;}int main() { int n; cin >> n; string s1, s2; cin >> s1 >> s2; for(int i = 0; i < n; ++ i) a[i] = s1[i] - '0'; for(int i = 0; i < n; ++ i) b[i] = s2[i] - '0'; sort(a, a + n); sort(b, b + n); int idx1 = 0, idx2 = 0; while(idx1 < n && idx2 < n) { if(a[idx1] > b[idx2]) idx2++; else idx1++, idx2++; } cout << n - idx1 << endl; idx1 = 0, idx2 = 0; sort(b, b + n, cmp); sort(a, a + n, cmp); int maxx = b[0]; while(idx1 < n && a[idx1] >= maxx) idx1++; while(idx1 < n && idx2 < n) { if(b[idx2] > a[idx1]) idx1++, idx2++; else idx1++; } cout << idx2 << endl;}
C - Alyona and Spreadsheet【DP】
戳上面链接直达题解BLOG
D - Cloud of Hashtags【贪心】
戳上面链接直达题解BLOG
阅读全文
0 0
- Codeforces Round #401 (Div. 2) (solve 4 of 5)
- Codeforces Round #426 (Div. 2) (solve 3 of 5)
- Codeforces Round #427 (Div. 2) (solve 5 / 6)
- Codeforces Round #425 (Div. 2) (solve 4)
- Codeforces Round #401 (Div. 2) B. Game of Credit Cards
- Codeforces Round #401 (Div. 2) D. Cloud of Hashtags
- Codeforces Round #401 (Div. 2)D. Cloud of Hashtags
- Codeforces Round #401 (Div. 2) D. Cloud of Hashtags
- Codeforces Round #401 (Div. 2)
- Codeforces Round #401 (Div. 2)
- Codeforces Round #401 (Div. 2)
- Codeforces Round #401 (Div. 2)
- Codeforces Round #188 (Div. 2) B. Strings of Power
- Codeforces Round #105 (Div. 2) D. Bag of mice
- Codeforces Round #209 (Div. 2) D. Pair of Numbers
- Codeforces Round #209 (Div. 2) D. Pair of Numbers
- Codeforces Round #209 (Div. 2), problem: (D) Pair of Numbers
- Codeforces Round #209 (Div. 2) D. Pair of Numbers
- HDU --- 1016 素数环 【简单深搜】
- STM8S103之tim1PWM输出
- 大白话字符串匹配的KMP算法
- 九的余数
- 2017年8月11日 星期五
- Codeforces Round #401 (Div. 2) (solve 4 of 5)
- java中构造方法
- Docker下用.NET Core写C#程序
- 进程控制编程之僵尸进程、守护进程创建、进程等待
- ubuntu1604环境下安装caffe及cuda80等相关组件实际操作流程
- Windows 7 Boot Updater 如何使用
- hpu 多校联萌(三) 1415
- 二叉树问题---统计所有可能的二叉树结构的种数
- Trie总结