Codeforces Round #321 B Kefa and Company
2015-09-23 20:08
393 查看
题意:给你n和d,n表示有几个人,d表示相差值,给出你每个人的价值和友谊值,让你求出在每个人之间相差不超过d的情况下,友谊值的最大值、
思路:模拟,依次向前找,找出一个那么便与之前我找过的友谊值的和值进行比较大小,最后输出最大值、之前写的结构体型似乎有问题、
因为在大数据的时候会超时,换成用容器就过了、48ms
AC代码:
思路:模拟,依次向前找,找出一个那么便与之前我找过的友谊值的和值进行比较大小,最后输出最大值、之前写的结构体型似乎有问题、
因为在大数据的时候会超时,换成用容器就过了、48ms
AC代码:
#include<cstdio> #include<cstring> #include<vector> #include<iostream> #include<algorithm> using namespace std; struct node { int x; int y; bool operator <(const node &a) const { return x<a.x; } }p; int n; long long sum,sun,d; int main() { while(scanf("%d %I64d",&n,&d)!=EOF){ vector<node> msq; for(int i=0;i<n;i++){ scanf("%d %d",&p.x,&p.y); msq.push_back(p); } sort(msq.begin(),msq.end()); int i=0; int j=0; sun=sum=msq[0].y; while(++i<n){ sun+=msq[i].y; while(msq[i].x-msq[j].x>=d){ sun-=msq[j++].y; } if(sun>sum) sum=sun; } if(sun>sum) sum=sun; printf("%I64d\n",sum); void clear(); } return 0; }
相关文章推荐
- url链接在手机短信模块中显示问题
- C#访问MySQL数据库的方法
- JavaScript两种单例模式
- Java 猜数字小游戏
- LeetCode(86) Partition List
- iOS-程序发布-32位和64位系统的兼容
- nodejs、npm、grunt——名词解释
- hdu 2602--Bone Collector(01背包)
- FocusChange-焦点变化监听事件
- LeetCode(86) Partition List
- Ubuntu服务器安装mysql数据库
- 【DIV+CSS】代码作业练习DIV+CSS太极阴阳图
- “新建Laravel项目”并“开启laravel”的操作
- 安卓:WebView简单使用
- UVA592字符串推断题加暴力假设搜索
- AVS2高清实时编码器问世,性能大幅超越HEVC/H.265编码器x265
- leetcode刷题,总结,记录,备忘 118
- Altium Designer 14 安装完整元件库
- Codeforces Round #321 A Kefa and First Steps
- iOS-APP发布应注意