CTU Open 2008(未完工)
来源:互联网 发布:淘宝企业店铺要纳税吗 编辑:程序博客网 时间:2024/06/05 12:04
链接:CTU Open 2008
【2014/05/15】今晚做了一下CTU 2008的这套题,最后的rank是3道题。基本是水题啊,我们做的是4个小时,如果完整做,我想应该还会出掉D题,主要是D题很繁琐,weikd写起都说烦。
A - Alea iacta est
B - On-Line Banking
【题意】纯模拟题,模拟银行存钱,取钱,转钱的操作。注意下细节~
#include <cstdio>#include <cstring>#include <algorithm>#include <map>#include <string>#define EPS 1e-8using namespace std;char str[1005];char cmd[1005];char name[1005],name1[1005];map<string,double> ac;void create(string id){ printf("create: "); if (ac.find(id)!=ac.end()) { printf("already exists\n"); } else { ac[id] = 0; printf("ok\n"); }}void deposit(string id, double x){ printf("deposit %.2f: ",x); if (ac.find(id)==ac.end()) { printf("no such account\n"); } else { ac[id] = ac[id]+x; printf("ok\n"); }}void withdraw(string id,double x){ printf("withdraw %.2f: ",x); if (ac.find(id)==ac.end()) { printf("no such account\n"); } else { if (ac[id]+EPS<x) { printf("insufficient funds\n"); } else { ac[id]=ac[id]-x; printf("ok\n"); } }}void transfer(string ida,string idb,double x){ printf("transfer %.2f: ",x); if (ac.find(ida)==ac.end()||ac.find(idb)==ac.end()) { printf("no such account\n"); } else { if (ida==idb) { printf("same account\n"); } else { if (ac[ida]+EPS<x) { printf("insufficient funds\n"); } else { ac[ida]=ac[ida]-x; ac[idb]=ac[idb]+x; char ia = *ida.rbegin(); char ib = *idb.rbegin(); if (ia==ib) { printf("ok\n"); } else { printf("interbank\n"); } } } }}int main(){ #ifdef HotWhite freopen("in.txt", "r", stdin); #endif int n; double mn; while(scanf("%d",&n)) { if (!n) break; ac.clear(); for (int i = 0; i < n; i++) { scanf("%s %lf",str,&mn); ac[str]=mn; } string s1,s2; while(scanf("%s",cmd)) { if (strcmp(cmd,"end")==0) break; if (strcmp(cmd,"create")==0) { scanf("%s",name); s1=name; create(s1); } if (strcmp(cmd,"deposit")==0) { scanf("%s%lf",name,&mn); s1=name; deposit(s1,mn); } if (strcmp(cmd,"withdraw")==0) { scanf("%s%lf",name,&mn); s1=name; withdraw(s1,mn); } if (strcmp(cmd,"transfer")==0) { scanf("%s%s%lf",name,name1,&mn); s1=name; s2=name1; transfer(s1,s2,mn); } } printf("end\n\n"); } printf("goodbye\n"); return 0;}
C - International Collegiate Programming Contest
D - Careful Declaration
E - Stock Exchange
【题意】每一组case给你一些买家的姓名和最高出价,还有卖家的姓名和最低售价。然后计算出所有成交信息。
【思路】水题,直接暴力模拟,比较价钱即可。代码如下:
#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int MAX = 1010;struct BID{ char name[25], type[5]; double price;};BID bid[MAX], buy[MAX], sell[MAX];int main() {#ifdef HotWhite freopen("in.txt", "r", stdin);#endif int N, flag; char issuer[12]; while(scanf("%d%s", &N, issuer) != EOF && N) { int cntb = 0, cnts = 0; for(int i=0; i<N; ++i) { scanf("%s%s%lf", bid[i].name, bid[i].type, &bid[i].price); if(strcmp(bid[i].type, "buy") == 0) { buy[cntb++] = bid[i]; } if(strcmp(bid[i].type, "sell") == 0) { sell[cnts++] = bid[i]; } } printf("%s\n", issuer); for(int i=0; i<N; ++i) { flag = 0; printf("%s:", bid[i].name); if(strcmp(bid[i].type, "buy") == 0) { for(int j=0; j<cnts; ++j) { if(sell[j].price <= bid[i].price) { printf(" %s", sell[j].name); flag = 1; } } } if(strcmp(bid[i].type, "sell") == 0) { for(int j=0; j<cntb; ++j) { if(buy[j].price >= bid[i].price) { printf(" %s", buy[j].name); flag = 1; } } } if(!flag) printf(" NO-ONE"); printf("\n"); } } return 0;}
F - Wooden Fence
G - Safe Gambling
H - Government Help
【题意】经济危机,政府给予bankA和bankB补助,补助是按照一包一包的算。总共有N包,为了公平起见,怎么分配才能使得最后bankA和bankB得到的补助之差最小。【思路】贪心策略,从小到大排序,先把最小的给A。然后从最大的开始先给B,再给A,依次分配下去,直到分完。代码如下:
#include <cstdio>#include <cstring>#include <algorithm>using namespace std;int a[50005];int main() {#ifdef HotWhite // freopen("in.txt", "r", stdin);#endif int n; while(scanf("%d",&n)) { if (!n) break; for (int i = 0; i < n; i++) { scanf("%d",&a[i]); } sort(a,a+n); printf("%d-A",a[0]); int k=0; for (int i = n-1; i >=1; i--,k++) { printf(" %d-%c",a[i],k&1?'A':'B'); } printf("\n"); } return 0;}
I - Tree Insertions
0 0
- CTU Open 2008(未完工)
- Android Test(未完工)
- 反调试(未完工)
- 五 串(未完工)
- CTU Open 2013
- CTU Open Contest 2016 Suspicious Samples(单调队列)
- [基于VBA编写] 钻孔数据表(未完工)
- The 14th Zhejiang University Programming Contest(未完工)
- CSS继承,层叠和特殊性(未完工)
- 坦克小作战 js版(未完工)
- 一个未完工的分析
- Codeforces Gym 101505(2016-2017 CTU Open Contest) D---群论、模拟
- ACM ICPC 2017 Warmup Contest 7(CTU Open Contest 2016)
- ACM ICPC 2017 Warmup Contest 7(CTU Open Contest 2016)
- POJ1789【CTU Open 2003】Truck History
- CTU Open 1999 Lloyd Fifteen Puzzle
- Flower Pots (CTU Open 2013 E题)
- CTU open Contest 2016 Tree Stands
- AXIS2:如何发布webservice .
- 工作中文件丢了怎么办
- Unity3D使用小技巧
- Robot Jacobian expressed in end effector frame
- 【htc法:IE-CSS3】CSS3支持IE6、IE7、IE8
- CTU Open 2008(未完工)
- Mysql
- Linux 内核阅读工具vim+ctags+cscope+taglist
- K-Max Sum
- 自己新建一个IDOC type和IDOC 触发程序
- ORA-02391: exceeded simultaneous SESSIONS_PER_USER limit
- php生成缩略图类,经典
- strtol()详解
- allegro中的文件类型