贪心的经典题型

该死的精度问题,WA了好几次,以后能用乘的绝不用除!!

#include<iostream>
#include<algorithm>
#include<cstdio> using namespace std; int main(){
int n,v,w,k,i;
int p[111],t[111];
cin>>k;
while(k--){
cin>>n>>v>>w;
for(i=0;i<n;i++)
scanf("%d",p+i);
sort(p,p+n);
t[0]=p[0]*100; //保留两位小数点
w*=100;
int d=0,kk=1,flag=0;
for(i=1;i<n;i++){
t[i]=t[i-1]+p[i]*100; //本来是 t[i]=(t[i-1]+p[i]*100)/(kk+1); 一直WA
if(t[i]<=w*(kk+1)){ //改成 w*(kk+1) 就过了
flag=1;
kk=i+1;
d=i;
}
}
if(!flag && t[0]>w)
cout<<"0 0.00"<<endl;
else
printf("%d %.2f\n",kk*v,(double) t[d]/(kk*10000.0)); }
return 0;
}

hdu 2570的更多相关文章

  1. --hdu 2570 迷瘴(贪心)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2570 Ac code: #include<stdio.h> #include<std ...

  2. HDU 2570:迷瘴

    迷瘴 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submiss ...

  3. hdu 2570 贪心

    贪心的经典题型 该死的精度问题,WA了好几次,以后能用乘的绝不用除!! #include<iostream> #include<algorithm> #include<c ...

  4. HDU——PKU题目分类

    HDU 模拟题, 枚举1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 ...

  5. 【转载】图论 500题——主要为hdu/poj/zoj

    转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...

  6. [转] HDU 题目分类

    转载来自:http://www.cppblog.com/acronix/archive/2010/09/24/127536.aspx 分类一: 基础题:1000.1001.1004.1005.1008 ...

  7. HDU ACM 题目分类

    模拟题, 枚举1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 104 ...

  8. HDU 5643 King's Game 打表

    King's Game 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5643 Description In order to remember hi ...

  9. 转载:hdu 题目分类 (侵删)

    转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...

随机推荐

  1. Java中HashMap遍历的两种方式

    Java中HashMap遍历的两种方式 转]Java中HashMap遍历的两种方式原文地址: http://www.javaweb.cc/language/java/032291.shtml 第一种: ...

  2. C++vector迭代器失效的问题

    转载:http://blog.csdn.net/olanmomo/article/details/38420907 转载:http://blog.csdn.net/stpeace/article/de ...

  3. UVA 11461 - Square Numbers

    题目:统计区间中的平方数个数. 分析: ... #include <stdio.h> #include <string.h> ]; int main() { int i, a, ...

  4. FreeSWITCH的TLS加密

    听着很高大上(实际也很实用)的加密机制,在FreeSWITCH里配置支持竟然这么简单! Greate FreeSWITCH and Greate Programmer! ① cd /usr/local ...

  5. vim功能使用

    转自:http://blog.csdn.net/xiajun07061225/article/details/7039413 vi与vim vi编辑器是所有Unix及Linux系统下标准的编辑器,他就 ...

  6. hdu 4217 Data Structure? 树状数组求第K小

    Data Structure? Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

  7. 【T-SQL系列】FOR XML PATH 语句的应用

    DECLARE @TempTable TABLE ( UserID INT , UserName ) ); INSERT INTO @TempTable ( UserID, UserName ) , ...

  8. mypc--------------->lspci,lsusb,meminfo cpuinfo ioports filesystems interrupts mounts net partitions pagetypeinfo slabinfo timer_list uptime version zoneinfo 等配置信息

    [user@username home]$ lspci00:00.0 Host bridge: Intel Corporation 4th Gen Core Processor DRAM Contro ...

  9. equals()和hashcode()

    默认调用的情况: 1.集合在存放对象时,首先判断hashcode(),再判断equals如果都是true,认为是相同的两个元素不进行存储. 删除对象时,将从hashcode指定位置查找再删除 2.在h ...

  10. xutils使用过程

    1,导入xutils的jar包 2,添加xutils需要使用的权限 <uses-permission android:name="android.permission.INTERNET ...