Milk
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 11183 Accepted Submission(s): 2685
Here are some rules:
1. Ignatius will never drink the milk which is produced 6 days ago or earlier. That means if the milk is produced 2005-1-1, Ignatius will never drink this bottle after 2005-1-6(inclusive).
2. Ignatius drinks 200mL milk everyday.
3. If the milk left in the bottle is less than 200mL, Ignatius will throw it away.
4. All the milk in the supermarket is just produced today.
Note that Ignatius only wants to buy one bottle of milk, so if the volumn of a bottle is smaller than 200mL, you should ignore it.
Given some information of milk, your task is to tell Ignatius which milk is the cheapest.
Each test case starts with a single integer N(1<=N<=100) which is the number of kinds of milk. Then N lines follow, each line contains a string S(the length will at most 100 characters) which indicate the brand of milk, then two integers for the brand: P(Yuan) which is the price of a bottle, V(mL) which is the volume of a bottle.
2 2 Yili 10 500 Mengniu 20 1000 4 Yili 10 500 Mengniu 20 1000 Guangming 1 199 Yanpai 40 10000
Mengniu Mengniu
找出最便宜的牛奶,用每次的 价格除以能喝的次数 sort排序取最小值就可以。
要注意1.每个牛奶最多喝5次。 我第一次一看以为是6次 WA了一次
2.sort排序 如果两个牛奶一样便宜 要按照体积大排序//因为 我没按体积排序 WA了
3.如果一次都不能喝的话,要默认价格为无穷大。。因为我设置的初始最大值比较小 WA了一次
总结 做题要认真!!
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
typedef struct a
{
string name;
int v;//体积
int price;//售价
double c;//每次喝的成本
}pp;
pp s[1000];
bool cmp(pp a,pp b)
{
if(a.c!=b.c) return a.c<b.c;
return a.v>b.v;
}
int main()
{
int cas,n,i,j,k,temp;
cin>>cas;
while(cas--)
{
cin>>n;
for(i=0;i<n;i++)
{
cin>>s[i].name>>s[i].price>>s[i].v;
temp=s[i].v/200;
if(temp>5) temp=5;
if(temp==0)
s[i].c=1000000;
else
s[i].c=(double)s[i].price/temp;
}
sort(s,s+n,cmp);
cout<<s[0].name<<endl;
}
}