谨以此水题作为我贪心的开始,并没有其他的意思……

http://acm.hdu.edu.cn/showproblem.php?pid=1009

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstdlib>
 4 #include <cstring>
 5 #include <algorithm>
 6 #include <cmath>
 7 #include <time.h>
 8 #include <string>
 9 #include <map>
10 #include <stack>
11 #include <vector>
12 #include <set>
13 #include <queue>
14 #define M  10000
15 #define maxn (1000 + 10)
16 #define pi acos(-1.0)
17 using namespace std;
18 struct room
19 {
20     double JavaBeans;
21     double Food;
22     double Average;
23 };
24 room op[maxn];
25 bool cmp(room a,room b)
26 {
27     return a.Average > b.Average;
28 }
29 int main()
30 {
31 //    freopen("in.txt","r",stdin);
32 //    freopen("in.txt","r",stdin);
33     double m,n,sum = 0;
34     while(scanf("%lf%lf",&m,&n) && !(m == -1 && n == -1))
35     {
36         sum = 0;
37         for(int i = 0; i < n; i ++)
38         {
39             scanf("%lf%lf",&op[i].JavaBeans,&op[i].Food);
40             op[i].Average = op[i].JavaBeans / op[i].Food;
41         }
42         sort(op,op + (int)n,cmp);
43         for(int i = 0; i < n; i ++)
44         {
45             if(m > op[i].Food)
46             {
47                 sum = sum + op[i].JavaBeans;
48                 m = m - op[i].Food;
49             }
50             else
51             {
52                 sum = sum + m / op[i].Food * op[i].JavaBeans;
53                 m = 0;
54             }
55         }
56         printf("%.3lf\n",sum);
57     }
58     return 0;
59 }
时间: 2024-08-22 09:19:01

谨以此水题作为我贪心的开始,并没有其他的意思……的相关文章

CodeForces 342B Xenia and Spies (水题模拟,贪心)

题意:给定 n 个间谍,m个区间,一个 s,一个f,然后从 s开始传纸条,然后传到 f,然后在每个 t 时间在区间内的不能传,问你最少的时间传过去. 析:这个题,就模拟一下就好,贪心策略,能传就传,找好方向,一直传就行,传到 f 就结束. 代码如下: #include <bits/stdc++.h> using namespace std; struct node{ int l, r, t; bool operator < (const node &p) const{ retur

HDU1009_FatMouse&amp;#39; Trade【贪心】【水题】

FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 44470    Accepted Submission(s): 14872 Problem Description FatMouse prepared M pounds of cat food, ready to trade with the cats g

LightOJ 1166 Old Sorting 置换群 或 贪心 水题

LINK 题意:给出1~n数字的排列,求变为递增有序的最小交换次数 思路:水题.数据给的很小怎么搞都可以.由于坐标和数字都是1~n,所以我使用置换群求循环节个数和长度的方法. /** @Date : 2017-07-20 14:45:30 * @FileName: LightOJ 1166 贪心 或 置换群 水题.cpp * @Platform: Windows * @Author : Lweleth ([email protected]) * @Link : https://github.co

HDU1009_FatMouse&#39; Trade【贪心】【水题】

FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 44470    Accepted Submission(s): 14872 Problem Description FatMouse prepared M pounds of cat food, ready to trade with the cats g

HDU1050(贪心水题)

Description The famous ACM (Advanced Computer Maker) Company has rented a floor of a building whose shape is in the following figure. The floor has 200 rooms each on the north side and south side along the corridor. Recently the Company made a plan t

POJ 3069 Saruman&#39;s Army(水题,简单的贪心)

[题意简述]:在一条直线上有N个点,每个点的位置分别是Xi,现从这N个点中选择若干个点给他们加上标记.使得,对每个点而言,在其距离为R的范围内都有带有标记的店,问   至少   要有几个被标记的点. [分析]:我们可以对这个点的序列简单的排序,按照从左到右,从小到大,然后对于最左边的这一个点,我们计算从这个点开始加上这个距离R可以到达的最远的但又小于这个距离R的点是哪一个,然后以这个点为基准,重复上述的过程,最终计算出点的个数. 详见代码: //244K 63Ms #include<iostre

BNUOJ 44662 水题 (贪心+优先级队列)

水题 Time Limit: 500ms Memory Limit: 32768KB This problem will be judged on HRBUST. Original ID: 2223 64-bit integer IO format: %lld      Java class name: Main Prev Submit Status Statistics Discuss Next 因为是有关于接水的问题,便简称为水题了(. N个人排队在M个出水口前接水,第i个人接水需时为t[i

hdu 5210 delete 水题

Delete Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5210 Description wld有n个数(a1,a2,...,an),他希望进行k次删除一个数的操作,使得最后剩下的n−k个数中有最多的不同的数,保证1≤n≤100,0≤k<n,1≤ai≤n(对于任意1≤i≤n) Input 多组数据(最多100组)对于每组数据:第一行:一个数n表示数的个数接下来一行:

Codeforces Round #256 (Div. 2/A)/Codeforces448A_Rewards(水题)解题报告

对于这道水题本人觉得应该应用贪心算法来解这道题: 下面就贴出本人的代码吧: 1 #include<cstdio> 2 #include<iostream> 3 using namespace std; 4 5 int a[3],b[3]; 6 7 int main(void) 8 { 9 int n; 10 int need = 0; 11 int sum1 = 0,sum2 = 0; 12 for(int i=1;i<=3;++i){ 13 scanf("%d&q