NEFU 617 贪心
2016-05-26 14:41
127 查看
NEFU 617
好多考试
Problem:617
Time Limit:1000ms
Memory Limit:65536K
Description
期末到了,一学期基本上都没上课的ACMer,们要开始预习了… 每一科的考试时间也都出来了,每一科的学分也都知道,如果没预习挂掉的话可是要扣学分的… 假设每预习一科需要一天的时间,自己安排复习时间,让挂掉的学分最少。
Input
输入数据有多组,每组三行,每行有多个整数,其中第一个整数为数字N(1<=N<=1000) (不要问我为什么考这么多),第二行有N个整数数T, Ti(1<=Ti<=1000)表示第i门课的考试时间,第三行有N个数,Ci(1<=Ci<=1000)表示第i门课的学分。
Output
每组数据输出一行,表示扣掉的最小的学分 .
Sample Input
3 3 3 3 10 5 1 3 1 3 1 6 2 3 7 1 4 6 4 2 4 3 3 2 1 7 6 5 4
Sample Output
0 3 5
Hint
Source
水题,贪心#include <iostream> #include <cstring> #include <algorithm> struct clas{ int lim; int gate; }; using namespace std; bool comp(struct clas x,struct clas y) { if(x.gate==y.gate) return x.lim<y.lim; return x.gate>y.gate; } int main() { bool vis[1005]; struct clas a[1005]; int n; while(cin>>n) { memset(vis,0,sizeof(vis)); memset(a,0,sizeof(a)); for(int i=0;i<n;i++) cin>>a[i].lim; for(int i=0;i<n;i++) cin>>a[i].gate; sort(a,a+n,comp); int ans=0; for(int i=0;i<n;i++) { int flag=1; for(int j=a[i].lim-1;j>=0;j--) { if(!vis[j]) { vis[j]=1; flag=0; break; } } if(flag) ans+=a[i].gate; } cout<<ans<<endl; } }
相关文章推荐
- 过滤器
- 等待网络服务是否可用
- python Flask restful框架
- 仿淘宝Banner:左右滑动ViewPager+最后一张滑动查看详情
- js获取select标签选中的值
- 同步容器类
- 关于程序设计中INF和MOD值的设定
- 关于广告联盟的高价词问题
- Spring MVC Request method 'POST' not supported错误
- Unity 2D射线与 3D射线 UI射线
- 中文python笔记
- github付钱吃亏记
- android网络安全
- document.write 存在几个问题?应该注意
- 修改第三方库内容,carsh提示"image not found"
- js中几种实用的跨域方法原理详解
- Java-常见错误集锦
- AgularJS中Unknown provider: $routeProvider错误的解决方法
- oracle 怎样查询某用户下的所有表的表名??
- int main(int argc,char* argv[])详解