Codeforces 985 E - Pencils and Boxes
思路:
dp
先排个序,放进一个袋子里的显然是一段区间
定义状态:pos[i]表示小于等于i的可以作为(放进一个袋子里的)一段区间起点的离i最近的位置
显然,初始状态:pos[i] = 1,1 <= i <= k
状态转移:
pos[i+1] = i+1 ,如果 a[i] - a[pos[i-k+1]] <= d , 因为在这种情况下pos[i-k+1] 到 i 可以放进一个袋子里,那么i+1就可以作为新的起点了
pos[i+1] = pos[i], 其他情况
最后只要判断pos[n+1] 等不等于 n+1 就可以判断是不是都能放进袋子里
代码:
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pi acos(-1.0)
#define LL long long
//#define mp make_pair
#define pb push_back
#define ls rt<<1, l, m
#define rs rt<<1|1, m+1, r
#define ULL unsigned LL
#define pll pair<LL, LL>
#define pii pair<int, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stout);
//head const int N = 5e5 + ;
int a[N], pos[N];
int main() {
int n, k, d;
scanf("%d%d%d", &n, &k, &d);
for (int i = ; i <= n; i++) scanf("%d", &a[i]);
sort(a+, a++n);
for (int i = ; i <= k; i++) pos[i] = ;
for (int i = k; i <= n; i++) {
int pre = pos[i-k+];
if(a[i] - a[pre] <= d) pos[i+] = i+;
else pos[i+] = pos[i];
//cout << i+1 << " " << pos[i+1] << endl;
}
if(pos[n+] == n+) printf("YES\n");
else printf("NO\n");
return ;
}
Codeforces 985 E - Pencils and Boxes的更多相关文章
- codeforces 985 E. Pencils and Boxes (dp 树状数组)
E. Pencils and Boxes time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes
Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes 题目连接: http://code ...
- codeforces 985E Pencils and Boxes(dp+思维)
E. Pencils and Boxes time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- Codeforces 985 最短水桶分配 沙堆构造 贪心单调对列
A B /* Huyyt */ #include <bits/stdc++.h> #define mem(a,b) memset(a,b,sizeof(a)) #define mkp(a, ...
- codeforces 985E Pencils and Boxes
题意: 把一个数组分成若干组,保证每组的size >= k并且一组中任意两个数字的差的绝对值 <= d,问存不存在这样的分法. 思路: 线性dp. 用dp[i]表示前i个数是否有分法. 设 ...
- 【24.67%】【codeforces 551C】 GukiZ hates Boxes
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 768F】 Barrels and boxes
http://codeforces.com/problemset/problem/768/F (题目链接) 题意 A,B两种物品可以装到栈中,每个栈只能存放一种物品,容量没有限制.现在讲所有栈排成一列 ...
- codeforces 551 C GukiZ hates Boxes
--睡太晚了. ..脑子就傻了-- 这个题想的时候并没有想到该这样-- 题意大概是有n堆箱子从左往右依次排列,每堆ai个箱子,有m个人,最開始都站在第一个箱子的左边, 每个人在每一秒钟都必须做出两种选 ...
- 【codeforces 768F】Barrels and boxes
[题目链接]:http://codeforces.com/problemset/problem/768/F [题意] 让你把f个food和w个wine装在若干个栈里面; 每个栈只能装food或者是wi ...
随机推荐
- GitHub使用笔记2:github常用操作
1: 绑定ssh keys 2:github新建仓库 echo "# SpringStack" >> README.md git init git add README ...
- 树莓派dhcp server
首先安装isc-dhcp-server apt-get install isc-dhcp-server 然后编辑配置文件,选择需要开启dhcp服务器的网卡 vi /etc/default/isc-dh ...
- centos6.5编译安装php7
1.安装依赖软件库: yum install -y libxml2-devel libtool* curl-devel libjpeg-devel libpng-devel freetype-deve ...
- 原生js封装的获取某一天是当年的第几周方法
function getWeek(str){ //str格式为yyy-mm-dd //周日归到了本周 var d=new Date(str); var day=d.getDay(); var orig ...
- 在VS2010中使用Git
转载:https://www.cnblogs.com/oec2003/archive/2012/11/13/2768860.html 一. 安装Git命令行,下载地址:http://code.goog ...
- C++进程间通信之剪贴板
转载:http://blog.csdn.net/hk627989388/article/details/53693636 转载:http://blog.csdn.net/heihei36/articl ...
- InstallShield安装包在Win7下权限问题的解决方案 (转载)
转载:http://blog.csdn.net/wuzhengqing1/article/details/6570149 转载:http://blog.csdn.net/brikoff/article ...
- CSS的再深入3(更新中···)
在前面,我们学习了标准文档流,但在实际制作的过程中,用标准文档流书写显然是不现实的,因此,我们来了解几种脱离标准文档流的方法: 1.float 浮动 float:left/right:(左浮/右浮) ...
- 高通平台framework,hal,kernel打开log【转】
本文转载自:https://blog.csdn.net/u010164190/article/details/78625636 .Add framework log #define LOG_NDEBU ...
- POJ-1038 Bugs Integrated, Inc. (状压+滚动数组+深搜 的动态规划)
本题的题眼很明显,N (1 <= N <= 150), M (1 <= M <= 10),摆明了是想让你用状态压缩dp. 整个思路如下:由于要填2*3或者3*2的芯片,那么就要 ...