卧槽人生中第一次cf的div2爆0
尼玛呀第一题凭什么不对!!!!!!!
要好好反省+看题解了T^T
正文:
Problem 1 Team Olympiad
大意就是给你几个数,每个数都是1,2,3,然后让你算最多能找出几组123成对的。
我的方法就是开一个二维数组分别对应数字和那个学生的位置,然后先算result,然后再遍历输出位置就好。
方法没问题啊。
这个题我竟然错了,好气啊T^T T^T T^T
问题出在数组越界,好友跟我说以后循环从1开始比较好记,然后那个小于号自然变成小于等于,但是这样一不小心就越界了。
可是问题在于我用eclipse编的时候它还是正常的结果,我靠果然掉段都是自找的么。
自己的智商那么低。。。。
#include <iostream> using namespace std; int num; int array[4][5001] = {{0}}; int main() { cin >> num; for (int i=1; i<=num; ++i) { int a; cin >> a; array[a][i] ++; } int a=0,b=0,c=0; for (int i=1; i<=5000; ++i) { a += array[1][i]; b += array[2][i]; c += array[3][i]; } int result1 = a; if (result1 > b) result1 = b; if (result1 > c) result1 = c; if (result1==0) { cout << result1; return 0; } cout << result1 << endl; for (int i=1; i<=result1; ++i) { int a=0,b=0,c=0; for (int i1 = 1; i1 <= 5000; ++i1) { if (array[1][i1] != 0) { a = i1; break; } } for (int i2 = 1; i2 <= 5000; ++i2) { if (array[2][i2] != 0) { b = i2; break; } } for (int i3 = 1; i3 <= 5000; ++i3) { if (array[3][i3] != 0) { c = i3; break; } } cout << a << " " << b << " " << c << endl; array[1][a] = 0; array[2][b] = 0; array[3][c] = 0; } return 0; }
Problem 2 Queue
大意就是有那么n个学生,都有学号,然后每个人的数据是记录了它前面一个人和后面一个人的学号,要最后输出几个人正确的顺序。
嗯我知道我题意描述不清不过没关系我看的清楚。
看了一下别人的一个还算清楚地代码然后改写了一下,觉得这道题没做出来的原因还是之前那第一题没做出来就一下子慌了,本来可以做出来的T^T
做法大概就是,首先有三个数组,我这里面的a是读入数据的数组,开始都是0,然后出现在第一个位置+1,出现在第二个位置-1,这样第一位的数字最后一定是1,最后一位的数字一定是-1。
然后b记载的是a后面2位置的人的学号。
c输出是循环的,就是从2开始每个都可以直接往b里面找了,这样速度也不算慢。
#include <iostream> using namespace std; int a[2000001]={0}; // a is the array that record whether number has appeared int b[2000001]={0}; // b records the number which is two position after a int c[2000001]={0}; // c is the final output array int main() { int num; cin >> num; for (int i=1; i<=num; ++i) { int n,m; cin >> n >> m; b[n] = m; a[n]++; // the first postion + 1 a[m]--; // the second position - 1 } // so the position that a[i] == 1 is the first person int first = 0; for (int i=1; i<=2000000; ++i) { if (a[i] == 1) { first = i; break; } } c[1] = first; // record first for (int i=2; i<=num; ++i) { c[i] = b[c[i-2]]; // key! just assign every number recursively } for (int i=1; i<=num; ++i) { cout << c[i] << " "; } return 0; }
需要提高的不只是代码能力还有心理啊
Problem 3 Hacking Cypher
卧槽我看完这道题也觉得十分简单怎么办。
但是比赛的时候我就想到用辗转相除啪啪啪,结果应该是不对,因为前两道都跪得十分惨所以也没有心情写这个。
还是正经写一下题意描述:
一个可以有很多位的整数,我们现在要将其分成两部分,给定a,b,然后第一部分能被a整除,第二部分能被b整除。
嗯解法:
好贱啊这些人都是读入的string,我没有经验不知道还能这样。上代码
#include <iostream> #include <string> using namespace std; int store[1001117] = { 0 }; int main() { string s; cin >> s; int len = s.length(); long long a, b; cin >> a >> b; long long md = 0; for (int i = 0; i < len; ++i) { md *= 10; md += (s[i] - '0'); md %= a; if (md == 0) { store[i]++; } } md = 0; long long tp = 1; for (int i = len - 1; i >= 0; i--) { md += ((s[i] - '0') * tp); md %= b; tp *= 10; tp %= b; if (md == 0) { if (store[i - 1] == 1 && (s[i] - '0') != 0) { cout << "YES\n"; for (int j = 0; j < i; j++) { cout << s[j]; } cout << endl; for (int j = i; j < len; j++) { cout << s[j]; } cout << endl; return 0; } } } cout << "NO\n"; return 0; }
首先先说这道题的做法