PAT (Advanced Level) 1070. Mooncake (25)
简单贪心。先买性价比高的。
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<string>
#include<algorithm>
using namespace std; double eps=1e-;
const int maxn=+;
int n;
struct X
{
double x;
double y;
}s[maxn];
double money; bool cmp(const X&a,const X&b)
{
return a.y/a.x>b.y/b.x;
} int main()
{
scanf("%d",&n);
scanf("%lf",&money);
for(int i=;i<=n;i++) scanf("%lf",&s[i].x);
for(int i=;i<=n;i++) scanf("%lf",&s[i].y);
sort(s+,s++n,cmp);
double ans=;
for(int i=;i<=n;i++)
{
if(money>=s[i].x)
{
ans=ans+s[i].y;
money=money-s[i].x;
}
else
{
ans=ans+money*s[i].y/s[i].x;
break;
}
}
printf("%.2lf\n",ans);
return ;
}
PAT (Advanced Level) 1070. Mooncake (25)的更多相关文章
- 【PAT甲级】1070 Mooncake (25 分)(贪心水中水)
题意: 输入两个正整数N和M(存疑M是否为整数,N<=1000,M<=500)表示月饼的种数和市场对于月饼的最大需求,接着输入N个正整数表示某种月饼的库存,再输入N个正数表示某种月饼库存全 ...
- PAT (Advanced Level) 1078. Hashing (25)
二次探测法.表示第一次听说这东西... #include<cstdio> #include<cstring> #include<cmath> #include< ...
- PAT (Advanced Level) 1029. Median (25)
scanf读入居然会超时...用了一下输入挂才AC... #include<cstdio> #include<cstring> #include<cmath> #i ...
- PAT (Advanced Level) 1010. Radix (25)
撸完这题,感觉被掏空. 由于进制可能大的飞起..所以需要开longlong存,答案可以二分得到. 进制很大,导致转换成10进制的时候可能爆long long,在二分的时候,如果溢出了,那么上界=mid ...
- PAT (Advanced Level) 1003. Emergency (25)
最短路+dfs 先找出可能在最短路上的边,这些边会构成一个DAG,然后在这个DAG上dfs一次就可以得到两个答案了. 也可以对DAG进行拓扑排序,然后DP求解. #include<iostrea ...
- PAT (Advanced level) 1003. Emergency (25) Dijkstra
As an emergency rescue team leader of a city, you are given a special map of your country. The map s ...
- PAT (Advanced Level) 1032. Sharing (25)
简单题,不过数据中好像存在有环的链表...... #include<iostream> #include<cstring> #include<cmath> #inc ...
- PAT (Advanced Level) Practice 1006 Sign In and Sign Out (25 分) 凌宸1642
PAT (Advanced Level) Practice 1006 Sign In and Sign Out (25 分) 凌宸1642 题目描述: At the beginning of ever ...
- PAT (Advanced Level) Practice 1002 A+B for Polynomials (25 分) 凌宸1642
PAT (Advanced Level) Practice 1002 A+B for Polynomials (25 分) 凌宸1642 题目描述: This time, you are suppos ...
随机推荐
- js第一天 点击按钮显示与隐藏
<!DOCTYPE html><html> <head> <meta charset="utf-8" /> <title> ...
- hdu_5802_Windows 10(贪心)
题目链接:hdu_5802_Windows 10 题意: 给你两个音量a,b,要让你将音量a变到音量b,up:每秒只能一次加1的音量,down:如果连续按x秒,那么就会减2x-1的音量 题解: 对于a ...
- OC画笔CGContextRef
1.画线 CGContextRef context = UIGraphicsGetCurrentContext();//context相当于画布 CGContextSetStrokeColorWith ...
- 判断数字 字母 isDigit(), isalpha()
判断是否是数字 isdigit isNumber 二者区别http://www.cnblogs.com/xiashengwang/p/3219925.html 需要包含头文件 #i ...
- Anaroid WebView详解大全
资源描述: 1.android提供了webView控件专门用来浏览网页.然后在程序中装载webView控件,设置属性,比如:颜色.字体.要访问的网址等.通过loadUrl方法设置当前webView需要 ...
- .NET Framework不同组件区别及安装注意事项
发布时间: 2012/7/14 11:52:37 严格细分起来,.NET Framework又有两个不同的组件,.NET Framework可再发行组件包(23MB左右)和.NET Framew ...
- 巧妙使用Contains()方法查找一个数是否在某堆数中
问题:要判断用户输入的一个数,或者是程序里方法的一个参数的值,或者是一个变量的值是否在某堆数中. 简洁写法:把这堆数放在list中,使用list的Contains()方法检查list是否包含这个数,取 ...
- ignite客户端找不到服务端的时候如何设置退出
ignite启动客户端时需要有服务端支持: Ignition.setClientMode(true); Ignition.start("ignite.xml"); 这里有个问题,当 ...
- linux视频学习7(ssh, linux启动过程分析,加解压缩,java网络编程)
回顾数据库mysql的备份和恢复: show databases; user spdb1; show tables; 在mysql/bin目录下 执行备份: ./mysqldump -u root - ...
- git 强制覆盖本地文件
git fetch --all git reset --hard origin/master git pull