codeforces 1706.D1 Chopping Carrots (Easy Version)
分析:
对于给定的一组序列a[], 我们可以暴力枚举a[]除以1到K 分别存储在vector<int>ver[maxn], vv 中;假设vv[i]是最小值,二分查找 ver[k]中第一个大于等于vv[i]的数,求出差值,求出所有的差值,并取出所有差值的最大值记为maxanswer,枚举求出maxanswer的最小值就行。
//AC code:
#include<bits/stdc++.h>
using namespace std;
const int maxn = 5e3 + 10;
const int N = 3e3 + 10;
const int inf = 1e6 + 10;
int a[maxn];
vector<int>ver[maxn];
int vis[N];
int visk[maxn];
void init(int n){
for(int i = 0; i <= n; i++) ver[i].clear();
}
int main(){
int t;
cin>>t;
while(t--){
vector<int>vv;
memset(visk, 0, sizeof(visk));
int n, k;
cin>>n>>k;
init(n);
for(int i = 1; i <= n; i++){
cin>>a[i];
}
for(int i = 1; i <= n; i++){
fill(vis, vis + N, 0);
for(int j = k; j >= 1; j--){
if(vis[a[i]/j] == 0) {
ver[i].push_back(a[i]/j);
vis[a[i]/j] = 1;
}
if(visk[a[i]/j] == 0){
vv.push_back(a[i]/j);
visk[a[i]/j] = 1;
}
}
}
sort(vv.begin(), vv.end());
int minans = inf;
for(int i = 0; i < vv.size(); i++){
int minval = vv[i];
int maxans = -inf; int f = 1;
for(int j = 1; j <= n; j++){
int num = lower_bound(ver[j].begin(), ver[j].end(), minval) - ver[j].begin();
if(num >= 0 && num < ver[j].size()){
maxans = max(maxans, ver[j][num] - minval);
}else{
f = 0;
break;
}
}
if(f == 1){
minans = min(maxans, minans);
}
}
printf("%d\n", minans);
}
return 0;
}
codeforces 1706.D1 Chopping Carrots (Easy Version)相关推荐
- D1. Chopping Carrots (Easy Version)
传送门 题意: 给你一个数组,a_1, a_2, a_3 \cdots, a_n, 长度为n, 和一个整数k, 另一个数组p_1, p_2, p_3, \cdots, p_n, 这两个数组的贡献是 m ...
- 1706D1 - Chopping Carrots (Easy Version)
原题链接: Problem - 1706D1 - Codeforces 题目描述: This is the easy version of the problem. The only differen ...
- D2. Chopping Carrots (Hard Version) (每日一题)
D2. Chopping Carrots (Hard Version) 题意:给定一个长度为n的数组a,要你拟定一个长度为n的数组p,使得下列公式求得的值最小 做法:固定最小值,考虑枚举使得最大值最小 ...
- Codeforces Round #809 (Div. 2)。D2. Chopping Carrots (Hard Version)
翻译: 这是这个问题的难解版本.版本之间的唯一区别是
- CodeForces - 1203F1 Complete the Projects (easy version)(贪心)
题目链接:点击查看 题目大意:现在有一个人,初始时有r元钱,现在有n个项目需要让他来解决,每个项目的门槛是a元钱,完成项目后的报酬是b元(报酬可以是负数),问能否在适当调整项目顺序后完成所有项目,能的 ...
- codeforces:E1. Divisible Numbers (easy version)【数论 + 复杂度计算 + 分解质因数】
目录 题目截图 题目分析 想法1:遍历所有可能的xy(tle) 想法2:遍历可能的x(accepted) 总结 题目截图 题目分析 想法1,遍历所有kab作为xy的所有可能值,找到其所有因子,然后看看 ...
- CodeForces Round #730 D1. RPD and Rap Sheet (Easy Version)题解
Codeforces Round #730 (Div. 2) 题意: t组数据,每组给一个n和k,(easy version里面k=2) 每一次系统会输入一个初始的密码(初始密码是一个在[0,n−1] ...
- CodeForces - 1543D1 RPD and Rap Sheet (Easy Version)(异或+交互)
题目链接:点击查看 题目大意:交互题猜密码,设原密码为 xxx,猜的密码为 yyy,如果没猜到,密码会自适应变成 zzz,满足 x⊕z=yx \oplus z=yx⊕z=y ,最多猜 nnn 次 题目 ...
- D1. Kirk and a Binary String (easy version)
题目链接:http://codeforces.com/contest/1204/problem/D1 D1. Kirk and a Binary String (easy version) time ...
最新文章
- 【组队学习】【27期】动手学数据分析
- Linux-NTP-Server+Client
- 数字转换成字符串进行连接
- java焦点图_javascript焦点图(能够自己主动切换 )
- 聊聊我的高效学习法,让你快速拿下算法、MySQL…每天只花半小时
- ptrace和wait的理解 (ptrace监控进程)
- ACM-ICPC中博弈论的一些小小总结
- python 读取配置文件的单元测试_单元测试
- Atitit 学习的本质 团队管理与培训的本质 attilax总结 v2
- android sdk集合 下载,Android SDK下载列表(含海内下载)-下
- C#代码混淆加壳利器ConfuserEx的使用
- 决策树的算法流程图(ID3/C4.5/CART)
- 七位高僧大德的临终开示,非大福报者不得见
- 理解服务器证书 CASSL
- 夏季多肉植物养注意事项!看了多肉长得又白又胖
- FPGA入门实验-基于状态机实现4位共阴极数码管显示超声波模块读数
- 四川企立方:拼多多团购要怎么申请团购点
- E18-D80NK红外避障传感器使用(附32单片机源码)
- 应届生和往届生,报名条件区别汇总!
- 2016国内热门的企业级SaaS应用
热门文章
- 【论文阅读】Multimodal Fusion with Co-Attention Networks for Fake News Detection --- 虚假新闻检测,多模态融合
- springboot高校学习资源共享系统java
- Win CE5.0背光驱动
- linux tar 7z,.tar.gz和.gz或.tar.7z和.7z有什么区别?
- 正式-日常作息(2020.11)
- eclipse下载网址收藏
- 新型计算机教学方式,电脑教学中的“新”
- C语言售货系统,自动售货机报告c语言课程设计.docx
- matlab for 语句事例,有关matlab里面for语句的使用。
- java 什么是ajax_什么是AJAX?