ACM大作业~~
来源:互联网 发布:鄂尔多斯网络推广招聘 编辑:程序博客网 时间:2024/06/06 12:39
我没退役啊,hahahhaa
写一些简答题
A
初等算术
Problem:B
Time Limit:1000ms
Memory Limit:10000K
Description
小学生在学多位数的加法时,是将两个数右对齐,然后从右往左一位一位地加。多位数的加法经常会有进位。如果对齐的位相加结果大于或等于十就给左边一位进一。对小学生来说,进位的判断是比较难的。你的任务是:给定两个加数,统计进位的次数,从而帮助老师评估加法的难度。
Input
输入文件中的每一行为两个无符号整数,少于10位。最后一行位两个0,表示输入结束。
Output
对输入文件(最后一行除外)每一行的两个加数,计算它们进行加法运算时进位的次数并输出。具体输出格式详见样例输出。
Sample Input
123 456555 555123 5940 0
Sample Output
No carry operation.3 carry operations.1 carry operation.
Hint
0时,输出No carry operation. 1时,输出1 carry operation. 大于1时,输出N carry operations.,注意:operations.和operation.
Source
#include <iostream>#include <string.h>using namespace std;int main(){ char s1[100],s2[100]; while(cin>>s1>>s2){ if(strcmp(s1,"0")==0&&strcmp(s2,"0")==0) break; int l1=strlen(s1); int l2=strlen(s2); int ans=0; int i=l1-1,j=l2-1; int tp=0; int a; for(;i>=0&&j>=0;i--,j--) { a=(s1[i]-'0')+(s2[j]-'0')+tp; if(a>=10) { ans++; tp=a%10; } } if(i){ for(int k=i;k>=0;k--) { a=s1[k]-'0'+tp; if(a>=10){ ans++; tp=a%10; } } } if(j){ for(int k=j;k>=0;k--) { a=s2[k]-'0'+tp; if(a>=10){ ans++; tp=a%10; } } } if(ans==0) { cout<<"No carry operation."<<endl; } else if(ans>=2) { cout<<ans<<" carry operations."<<endl; } else if(ans==1){ cout<<ans<<" carry operation."<<endl; } } return 0;}
老鼠的旅行
Problem:C
Time Limit:1000ms
Memory Limit:65536K
Description
一只老鼠有M磅猫食,然后在N个房间里面用猫食换JavaBean,房间i中能用F[i]磅的猫食来换J[i]磅的JavaBean,而且老鼠可以在一个房间里根据一定比例a%来换取JavaBean.现在他是这任务分配给你:告诉他,他的JavaBeans的获取能最多。
Input
The input consists of multiple test cases. Each test case begins with a line containing two non-negative integers M and N. Then N lines follow, each contains two non-negative integers J[i] and F[i] respectively. The last test case is followed by two -1′s. All integers are not greater than 1000.M是开始时老鼠有的猫食!
Output
For each test case, print in a single line a real number accurate up to 3 decimal places, which is the maximum amount of JavaBeans that FatMouse can obtain.
Sample Input
5 37 24 35 220 325 1824 1515 10-1 -1
Sample Output
13.33331.500
Hint
贪心
Source
ZJCPC2004
#include <iostream>#include <algorithm>#include <stdio.h>using namespace std;struct node{ double f,j,v;} d[1005];bool cmp(node a1,node a2){ return a1.v>a2.v;}int main(){ double m;//f[1005],j[1005],; int n; while(cin>>m>>n) { if(m==-1&&n==-1) break; for(int i=0; i<n; i++) { cin>>d[i].f>>d[i].j; d[i].v=d[i].f/d[i].j; } sort(d,d+n,cmp); double ans=0.0; for(int i=0; i<n; i++) { // cout<<d[i].v<<" "<<m<<endl; if(m>=d[i].j) { m-=d[i].j; ans+=d[i].f; } else { ans+=m*d[i].v; m=0; } } printf("%.3lf\n",ans); } return 0;}
阅读全文
0 0
- ACM大作业~~
- 大作业
- 大作业
- ACM作业 找回手机
- 北大ACM作业练习 1001
- 完成数据结构大作业
- 数据库大作业
- Web程序设计大作业
- 人工智能大作业啊。。。
- 大作业进度
- 数据库大作业
- Java大作业要求
- java 大作业报告
- 操作系统大作业笔记
- 数据结构大作业
- 软件工程大作业
- 数据库大作业总结
- SMIL大作业
- Linux下的ioctl()函数详解
- linux类似命令界面如何出来
- java的JsonObject对象提取值
- 我们该如何理解卷积?
- Linux网络编程--使用epoll模型同时处理tcp和udp服务
- ACM大作业~~
- Mybatis Mapper动态代理方法 即 只写Dao接口 不谢Dao的实现类
- 数据库尽量不用字符串存储非字符串数据
- 范型&&诡异异常
- com.huawei.lcagent.client.LogCollectManager.getUserType
- Android 商品广告轮播图 图片轮播
- ffmpeg在centos7上的编译
- android studio:打jar包、apk包
- 问句相似度