``````
#include <iostream>
#include <iomanip>
#include<algorithm>
#define MAX 1000
using namespace std;
struct room{
int javabeen;
int catfood;
double price;
};
room a[MAX];
int M,N,n0,n1;
bool rule(room x,room y){
return x.price<y.price;
}
int main(){
while(cin>>M>>N && !(M==-1 && N==-1)){
for(int i=0;i<N;i++){
cin>>n0>>n1;
a[i].javabeen=n0;
a[i].catfood=n1;
if(n0==0) a[i].price=-1;
a[i].price=(double)n1/n0;
}
sort(a,a+N,rule);
double get=0.0;
for(int i=0;i<N;i++){
if(a[i].price==-1) break;
if(M>=a[i].catfood){
M-=a[i].catfood;
get+=a[i].javabeen;
}
else{
get=get+(double)M/a[i].price;
M=0;
break;
}
}
cout<<fixed<<setprecision(3)<<get<<endl;
}
system ("pause");
return 0;
}

``````

1个回答

acm水题 二叉树模拟 hdu5444，能想到的测试数据都测了还是WA，求大神
1）我的代码（题目连接：http://acm.hdu.edu.cn/showproblem.php?pid=5444，也有复制内容在代码下面） ``` #include <iostream> #include <string.h> using namespace std; const int maxn=1010; char record[maxn]; int sum=0; struct tree{ int left; int right; }tree_1[maxn]; void build_tree(int root,int num) { if(root>num&&!tree_1[root].right){ tree_1[root].right=num; } if(root<num&&!tree_1[root].left){ tree_1[root].left=num; } if(root>num){ build_tree(tree_1[root].right,num); } if(root<num){ build_tree(tree_1[root].left,num); } } void dfs_tree(int root,int num) { if(num==root&&!sum){ sum=1; return ; } if(num<root&&tree_1[root].right){ record[sum++]='E'; dfs_tree(tree_1[root].right,num); } else if(num>root&&tree_1[root].left){ record[sum++]='W'; dfs_tree(tree_1[root].left,num); } } int main() { int kase;cin>>kase; while(kase--){ int n;cin>>n; int root;cin>>root; n--; while(n--){ int room_num;cin>>room_num; build_tree(root,room_num); } int m;cin>>m; record[0]='\0'; while(m--){ int bk_num;cin>>bk_num; dfs_tree(root,bk_num); for(int i=0;i<sum;i++){ cout<<record[i]; } cout<<endl; memset(record,0,sizeof(record)); record[0]='\0'; sum=0; } memset(tree_1,0,sizeof(tree_1)); } } ``` 2） Problem Description Elves are very peculiar creatures. As we all know, they can live for a very long time and their magical prowess are not something to be taken lightly. Also, they live on trees. However, there is something about them you may not know. Although delivering stuffs through magical teleportation is extremely convenient (much like emails). They still sometimes prefer other more “traditional” methods. So, as a elven postman, it is crucial to understand how to deliver the mail to the correct room of the tree. The elven tree always branches into no more than two paths upon intersection, either in the east direction or the west. It coincidentally looks awfully like a binary tree we human computer scientist know. Not only that, when numbering the rooms, they always number the room number from the east-most position to the west. For rooms in the east are usually more preferable and more expensive due to they having the privilege to see the sunrise, which matters a lot in elven culture. Anyways, the elves usually wrote down all the rooms in a sequence at the root of the tree so that the postman may know how to deliver the mail. The sequence is written as follows, it will go straight to visit the east-most room and write down every room it encountered along the way. After the first room is reached, it will then go to the next unvisited east-most room, writing down every unvisited room on the way as well until all rooms are visited. Your task is to determine how to reach a certain room given the sequence written on the root. For instance, the sequence 2, 1, 4, 3 would be written on the root of the following tree. Input First you are given an integer T(T≤10) indicating the number of test cases. For each test case, there is a number n(n≤1000) on a line representing the number of rooms in this tree. n integers representing the sequence written at the root follow, respectively a1,...,an where a1,...,an∈{1,...,n}. On the next line, there is a number q representing the number of mails to be sent. After that, there will be q integers x1,...,xq indicating the destination room number of each mail. Output For each query, output a sequence of move (E or W) the postman needs to make to deliver the mail. For that E means that the postman should move up the eastern branch and W the western one. If the destination is on the root, just output a blank line would suffice. Note that for simplicity, we assume the postman always starts from the root regardless of the room he had just visited. Sample Input 2 4 2 1 4 3 3 1 2 3 6 6 5 4 3 2 1 1 1 Sample Output E WE EEEEE

acm题，测试很多数据都没错，一提交就WA
/* Judge Info Memory Limit: 32768KB Case Time Limit: 1000MS Time Limit: 1000MS Judger: Number Only Judger Description We are given a integer sequence, your job is find the length of the longest contiguous subsequence that is strictly increasing or strictly decreasing. Input First number T (1<=T<=100), represent how many test cases. For each test case the first number is N (1=< N <= 50). Then N, positive integers are followed, all of them are less than 101. Output For each test case output the answer in one line. Sample Input 3 3 1 1 1 3 1 2 3 4 4 3 2 1 Sample Output 1 3 4 */ #include<stdio.h> int main() { int b[10000]; int max; int sheng,jiang;//记录升序和降序的长度 int T; int N; int i; scanf("%d",&T); while(T--) { sheng=1;jiang=1;max=1; scanf("%d",&N); for(i=0;i<N;i++) scanf("%d",&b[i]); for(i=0;i<N-1;i++) { if(b[i]<b[i+1]) { sheng++; if(sheng>max) max=sheng; jiang=1; } else if(b[i]>b[i+1]) { jiang++; if(jiang>max) max=jiang; sheng=1; } } printf("%d\n",max); } return 0; }

ACM hdoj1084测试了很多数据，提交就wa
http://acm.hdu.edu.cn/showproblem.php?pid=1084 代码如下 #include <iostream> #include <string.h> using namespace std; struct score{ int p; string t; }; int main() { int t; while(cin>>t && t>=0){ score sco[100]; // memset(sco,0,sizeof(sco)); for(int i=0;i<t;i++){ sco[i].t.clear(); cin>>sco[i].p>>sco[i].t; } for(int i=0;i<t;i++){ bool flag = true; int first=0,last=0; for(int j=0;j<t;j++){ if(sco[i].p==sco[j].p&&sco[i].t<sco[j].t){ first ++; } if(sco[i].p==sco[j].p&&sco[i].t>sco[j].t){ last++; } if(first<=last&&first+last!=0) flag = false; } if(flag==true){ if(sco[i].p == 5) cout<<"100"<<endl; else if(sco[i].p == 0) cout<<"50"<<endl; else cout<<(sco[i].p+5)*10 +5<<endl; } else{ if(sco[i].p == 5) cout<<"100"<<endl; else if(sco[i].p == 0) cout<<"50"<<endl; else cout<<(sco[i].p+5)*10<<endl; } } cout<<endl; } return 0; }
zoj 1056 一道简单的acm，测试数据对，就是不通过 用的c++
Worm is an old computer game. There are many versions, but all involve maneuvering a "worm" around the screen, trying to avoid running the worm into itself or an obstacle. We'll simulate a very simplified version here. The game will be played on a 50 x 50 board, numbered so that the square at the upper left is numbered (1, 1). The worm is initially a string of 20 connected squares. Connected squares are adjacent horizontally or vertically. The worm starts stretched out horizontally in positions (25, 11) through (25, 30), with the head of the worm at (25, 30). The worm can move either East (E), West (W), North (N) or South (S), but will never move back on itself. So, in the initial position, a W move is not possible. Thus the only two squares occupied by the worm that change in any move are its head and tail. Note that the head of the worm can move to the square just vacated by the worm's tail. You will be given a series of moves and will simulate the moves until either the worm runs into itself, the worm runs off the board, or the worm successfully negotiates its list of moves. In the first two cases you should ignore the remaining moves in the list. Input There will be multiple problems instances. The input for each problem instance will be on two lines. The first line is an integer n (<100) indicating the number of moves to follow. (A value of n = 0 indicates end of input.) The next line contains n characters (either E, W, N or S), with no spaces separating the letters, indicating the sequence of moves. Output Generate one line of output for each problem instance. The output line should be one of the follow three: The worm ran into itself on move m. The worm ran off the board on move m. The worm successfully made all m moves. Where m is for you to determine and the first move is move 1. Sample Input 18 NWWWWWWWWWWSESSSWS 20 SSSWWNENNNNNWWWWSSSS 30 EEEEEEEEEEEEEEEEEEEEEEEEEEEEEE 13 SWWWWWWWWWNEE 0 Sample Output The worm successfully made all 18 moves. The worm ran into itself on move 9. The worm ran off the board on move 21. The worm successfully made all 13 moves. 初始位置头是24,30，尾是24,11 以下是WA的代码 #include<iostream> using namespace std; int main() { int orders; while(cin >> orders && orders!= 0) { bool s2[50][50]; for(int i = 0; i < 50; i++) { for(int j = 0; j < 50; j++) { s2[i][j] = true; } } int a = 24, b = 29, c = 24, d = 10; s2[a][b] = true; for(int i = 10; i < 29; i++) { s2[24][i] = false; } string ord; cin >> ord; for(int i = 0; i < orders; i++) { if(ord[i] == 'N') {s2[a][b] = false; a--;} else if(ord[i] == 'S') {s2[a][b] = false; a++;} else if(ord[i] == 'E') {s2[a][b] = false; b++;} else if(ord[i] == 'W') {s2[a][b] = false; b--;} //处理蛇尾 if(i < 19 && i != orders - 1) { s2[c][d] = true; d++; } else if(i >= 19 && i != orders - 1) { if(ord[i - 20] == 'N') { s2[c][d] = true; c--; } else if(ord[i - 20] == 'S') { s2[c][d] = true; c++; } else if(ord[i - 20] == 'E') { s2[c][d] = true; d++; } else if(ord[i - 20] == 'W') { s2[c][d] = true; d--; } } else if(i == orders - 1) { cout << "The worm successfully made all " << orders << " moves." <<endl; break; } if(a < 0 || a > 49 || b < 0 || b > 49) { cout << "The worm ran off the board on move " << i + 1 << "." <<endl; break; } else { if(s2[a][b]) { continue; } else { cout << "The worm ran into itself on move " << i + 1 <<"."<<endl; break; } } } } return 0; }
ACM CodeForces 2A - Winner 求大神指导

Description Gardon和小希玩了一个游戏，Gardon随便想了一个数A（首位不能为0），把它去掉一个数字以后得到另外一个数B，他把A和B的和N告诉了小希，让小希猜想他原来想的数字。不过为了公平起见，如果小希回答的数虽然不是A，但同样能达到那个条件（去掉其中的一个数字得到B，A和B之和是N），一样算小希胜利。而且小希如果能答出多个符合条件的数字，就可以得到额外的糖果。 所以现在小希希望你编写一个程序，来帮助她找到尽可能多的解。 例如，Gardon想的是A=31,B=3 告诉小希N=34， 小希除了回答31以外还可以回答27（27+7=34）所以小希可以因此而得到一个额外的糖果。 Input 输入包含多组数据，每组数据一行，包含一个数N(1<=N<=10^9)，文件以0结尾。 Output 对于每个输入的N，输出所有符合要求的解（按照大小顺序排列）如果没有这样的解，输出"No solution." Sample Input Original Transformed 34 152 21 0 Sample Output Original Transformed 27 31 32 126 136 139 141 No solution. 下面是我的代码，我测试的正确啊，可是交上去总是WA #include<stdio.h> void BubbleSort(int array[],int n) { int i,j,temp; for(i=0; i<n-1; i++) { for(j=0; j<n-1-i; j++) { if(array[j]>array[j+1]) { temp=array[j]; array[j]=array[j+1]; array[j+1]=temp; } } } } int s[108]; int main() { int n,a,b,c; while(scanf("%d",&n)!=EOF&&n) { int cnt=0,k; for(k=1;k<=n;k*=10) { c=n/k/11; b=n/k%11; if(b+c&&b!=10) { a=(n-b*k-c*11*k)/2; if(n==a*2+b*k+c*11*k)s[cnt++]=a+b*k+c*10*k; } b--; if(b+c&&b>=0) { a=(n-b*k-c*11*k)/2; if(n==a*2+b*k+c*11*k)s[cnt++]=a+b*k+c*10*k; } } if(cnt==0)printf("no solution.\n"); else { BubbleSort(s,cnt); printf("%d",s[0]); int i; for(i=1;i<cnt;i++) { if(s[i]!=s[i-1])printf(" %d",s[i]); } printf("\n"); } } return 0; }

Linux(服务器编程):15---两种高效的事件处理模式（reactor模式、proactor模式）

C语言魔塔游戏

Python爬虫爬取淘宝，京东商品信息

Java工作4年来应聘要16K最后没要,细节如下。。。

2020年，冯唐49岁：我给20、30岁IT职场年轻人的建议

##1、骇客帝国(1999) 概念：在线/离线，递归，循环，矩阵等 剧情简介： 不久的将来，网络黑客尼奥对这个看似正常的现实世界产生了怀疑。 他结识了黑客崔妮蒂，并见到了黑客组织的首领墨菲斯。 墨菲斯告诉他，现实世界其实是由一个名叫“母体”的计算机人工智能系统控制，人们就像他们饲养的动物，没有自由和思想，而尼奥就是能够拯救人类的救世主。 可是，救赎之路从来都不会一帆风顺，到底哪里才是真实的世界？
Python绘图，圣诞树，花，爱心 | Turtle篇

CPU对每个程序员来说，是个既熟悉又陌生的东西？ 如果你只知道CPU是中央处理器的话，那可能对你并没有什么用，那么作为程序员的我们，必须要搞懂的就是CPU这家伙是如何运行的，尤其要搞懂它里面的寄存器是怎么一回事，因为这将让你从底层明白程序的运行机制。 随我一起，来好好认识下CPU这货吧 把CPU掰开来看 对于CPU来说，我们首先就要搞明白它是怎么回事，也就是它的内部构造，当然，CPU那么牛的一个东

2020年1月17日，国家统计局发布了2019年国民经济报告，报告中指出我国人口突破14亿。 猪哥的朋友圈被14亿人口刷屏，但是很多人并没有看到我国复杂的人口问题：老龄化、男女比例失衡、生育率下降、人口红利下降等。 今天我们就来分析一下我们国家的人口数据吧！ 一、背景 1.人口突破14亿 2020年1月17日，国家统计局发布了 2019年国民经济报告 ，报告中指出：年末中国大陆总人口（包括31个
2019年除夕夜的有感而发

2020年的1月，我辞掉了我的第一份工作

By 超神经场景描述：昨天 2 月 3 日，是大部分城市号召远程工作的第一天，全国有接近 2 亿人在家开始远程办公，钉钉上也有超过 1000 万家企业活跃起来。关键词：十一出行 人脸...
Java基础知识点梳理
Java基础知识点梳理 摘要： 虽然已经在实际工作中经常与java打交道，但是一直没系统地对java这门语言进行梳理和总结，掌握的知识也比较零散。恰好利用这段时间重新认识下java，并对一些常见的语法和知识点做个总结与回顾，一方面为了加深印象，方便后面查阅，一方面为了学好java打下基础。 Java简介 java语言于1995年正式推出，最开始被命名为Oak语言，由James Gosling（詹姆
2020年全新Java学习路线图，含配套视频，学完即为中级Java程序员！！

B 站上有哪些很好的学习资源?

Web播放器解决了在手机浏览器和PC浏览器上播放音视频数据的问题，让视音频内容可以不依赖用户安装App，就能进行播放以及在社交平台进行传播。在视频业务大数据平台中，播放数据的统计分析非常重要，所以Web播放器在使用过程中，需要对其内部的数据进行收集并上报至服务端，此时，就需要对发生在其内部的一些播放行为进行事件监听。 那么Web播放器事件监听是怎么实现的呢？ 01 监听事件明细表 名...
【CSDN学院出品】 你不可不知的JS面试题（分期更新……）
1、JS中有哪些内置类型？ 7种。分别是boolean、number、string、object、undefined、null、symbol。 2、NaN是独立的一种类型吗？ 不是。NaN是number类型。 3、如何判断是哪个类型？ Object.prototype.toString.call()，返回为[object Type]。 现在我们来验证一下。 Object.prototype.toS...
3万字总结，Mysql优化之精髓

HTML5适合的情人节礼物有纪念日期功能

Git笔记（3） 安装配置
Git的安装，基础配置以及如何获取帮助
Python新型冠状病毒疫情数据自动爬取+统计+发送报告+数据屏幕（三）发送篇

Java中国银行系统ATM机自助实现登录、开户、存款、取款、转账、查询余额、修改预留手机号、注销账号等功能（Ziph）
@Java 最全功能的银行ATM机自助（严谨性） 大家好，我是Ziph！ 此小项目的体会真是，为了实现功能是不择手段啊，为了实现和完善功能，码了一遍又一遍（找Bug），测试了N多次功能，测试好了发个博。OK，点个赞呗！哈哈，废话少说向下看吧！ 题目： 中国银行系统ATM机自助实现登录、开户、存款、取款、转账、查询余额、修改预留手机号、注销账号等功能 此小项目主要是运用了增删改查知识、循环结构知识、...