USACO 1.1

来源:互联网 发布:mac 大写灯不亮 编辑:程序博客网 时间:2024/06/16 16:25

用了1天才A掉USACO 1.1的题目,现在简直弱爆了。


都是水题没啥好说的。


Your Ride Is Here

/*ID:xueyifa4LANG:C++TASK:ride*/#include <iostream>#include <fstream>#include <cstring>#include <cstdlib>#include <cstdio>using namespace std;int main(){FILE *fin = fopen("ride.in", "r");FILE *fout = fopen("ride.out", "w");char ch;int a = 1, b = 1;while ((ch = fgetc(fin)) != '\n')a = (a * (ch - 'A' + 1)) % 47;while ((ch = fgetc(fin)) != '\n')b = (b * (ch - 'A' + 1)) % 47;if (a == b)fprintf(fout, "GO\n");else fprintf(fout, "STAY\n");return 0;}



Greedy Gift Givers
/*ID:xueyifa4TASK:gift1LANG:C++*/#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <map>#include <vector>#include <fstream>using namespace std;int n, money[10]={0};string name[10];int get_name(string s){for (int i = 0; i != n; ++ i)if (name[i] == s)return i;}#define fin cin#define fout coutint main(){ifstream fin("gift1.in");ofstream fout("gift1.out");cin >> n;for (int i = 0; i != n; ++ i)cin>>name[i];for (int i = 0; i != n; ++ i){int init, t, gei;string tmp_name;cin >> tmp_name;cin >> init >> t;if (!t)continue;money[get_name(tmp_name)] -= init/t*t;init /= t;while (t --){string tmp;cin >> tmp;money[get_name(tmp)] += init;}}for (int i = 0; i != n; ++ i)cout<<name[i]<<" "<<money[i]<<endl;return 0;}
这题想说一下。。本来想用map直接来检索姓名的,但是好像完全忘记怎么用了。。就用了O(n)的搜索,回头把C++ PRIMER重新读完,应该能都回忆起来了...


Friday the Thirteenth

/*ID:xueyifa4PROG:fridayLANG:C++*/#include <iostream>#include <fstream>#include <cstring>#include <cstdlib>#include <cstdio>using namespace std;int mouth[13] = {0, 31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};const int RUN = 29;const int PING = 28;int TOT[8] = {0};int check (int k){if (!(k % 100))if (!(k % 400))return RUN;else return PING;if (!(k % 4))return RUN;return PING;}int main(){ofstream fout("friday.out");ifstream fin("friday.in");int n, w = 2;fin >> n;for (int i = 0; i != n; ++ i){mouth[2] = check(1900 + i);for (int j = 1; j <= 12; ++ j)for (int k = 1; k <= mouth[j]; ++ k){w = (w + 1) % 7;if (!w)w = 7;if (k == 13)++TOT[w];}}for (int i = 1; i != 7; ++ i)fout<<TOT[i]<<" ";fout<<TOT[7]<<endl;return 0;}




Broken Necklace

这题我写的还是比较傻逼的,好像比别人的长好多的样子。我不会告诉你,我写这题用了3个小时QAQ,  提交还WA掉一次...
/*ID:xueyifa4PROG:beadsLANG:C++*/#include <cstdio>#include <fstream>#include <cstdlib>#include <cstring>#include <iostream>#include <vector>using namespace std;int n, flag1 = 0, flag2 = 0, ans = 0;const int max_n = 350 * 4;char c[max_n];class Point{public:int b, r;int s(){return max(b, r);}Point():b(5), r(5){}Point(char k){switch (k){case 'w': b = 1, r = 1; break;case 'b': b = 1; r = 0; break;case 'r': r = 1; b = 0; break;}}}f1[max_n], f2[max_n];#define cin fin#define cout foutint main(){ifstream fin("beads.in");ofstream fout("beads.out");cin >> n;for (int i = 0; i != n; ++ i)cin >> c[i];for (int i = 0; i != n; ++ i)f1[i] = Point(c[i]);for (int i = 0; i != n; ++ i)flag1 += f1[i].b, flag2 += f1[i].r;memmove(c + n, c, sizeof(char) * n);memmove(c + n + n, c,sizeof(char) * n);memmove(f1 + n, f1, sizeof(Point) * n);memmove(f1 + n + n, f1, sizeof(Point) * n);memmove(f2 , f1, sizeof(Point) * n * 3);for (int i = 1; i != 3 * n; ++ i){if (f1[i].b)f1[i].b += f1[i - 1].b;if (f1[i].r)f1[i].r += f1[i - 1].r;}for (int i = 3 * n - 2; i >= 0; -- i){if (f2[i].b)f2[i].b += f2[i + 1].b;if (f2[i].r)f2[i].r += f2[i + 1].r;}for (int i = n; i != n * 2; ++ i)ans = max(ans, f1[i].s() + f2[i + 1].s());cout << min(ans, n) << endl;return 0;}



0 0
原创粉丝点击