ccpc秦皇岛部分题解
A.
题意:就是有一个大桌子,环绕有顺势站1~m共m个座位,n个选手坐在部分位置上。然后如果有一个人a了一道题,却没有立刻发气球给他,他产生怒气值是发气球给他的时间减去a题时间。现在有一个机器人顺时针环绕桌子发球,每个单位时间走过一个位置。问机器人在哪个位置开始发气球总怒气值最小,输出最小怒气值。
其实是个傻逼思维题。假如他从位置m开始发气球,对于每个位置i,他到达的时间为k*m+i,所以对于每个它在时刻t a的题,他需要等待t-(k*m+i)中最小的正整数时间。随便算算就能知道每一题从m位置开始具体产生的怒气值,从而算出怒气总值作为初始值(当然从其他位置也行)。然后他往逆时针移动一个位置开始,相当于所有a题时间在%m的意义下+1。因此我们从小到大排个序,从最后一个数字往第一个数字遍历一遍,每次的操作都是把该为数字加到0的数加到所有题上,算算总的怒气值,在这里面一定产生一个最小的怒气值。
#include<bits/stdc++.h>
#define clr(x) memset(x,0,sizeof(x))
#define clr_1(x) memset(x,-1,sizeof(x))
#define mod 1000000007
#define LL long long
using namespace std;
const int N=;
int n,m,q,k,T,u,v;
int pos[N],info[N];
LL pp,qq,tt,ans,all;
int main()
{
scanf("%d",&T);
while(T--)
{
scanf("%d%d%d",&n,&m,&q);
for(int i=;i<=n;i++)
{
scanf("%d",&pos[i]);
if(pos[i]==m)
pos[i]=;
}
all=;
for(int i=;i<=q;i++)
{
scanf("%d%d",&u,&v);
v=v%m;
info[i]=(pos[u]-v+m)%m;
all+=info[i];
}
n=q;
sort(info+,info+n+);
LL qq=;
ans=all;
for(int i=n;i>=;i--)
{
pp=m-(info[i]+qq);
all-=(LL)info[i]+qq;
all+=pp*(n-);
qq+=pp;
if(all<ans)
ans=all;
}
printf("%lld\n",ans);
}
return ;
}
ccpc秦皇岛部分题解的更多相关文章
- 2017 CCPC秦皇岛 E题 String of CCPC
BaoBao has just found a string of length consisting of 'C' and 'P' in his pocket. As a big fan of ...
- 2017 CCPC秦皇岛 A题 A Ballon Robot
The 2017 China Collegiate Programming Contest Qinhuangdao Site is coming! There will be teams parti ...
- 2017 CCPC 哈尔滨站 题解
题目链接 2017 CCPC Harbin Problem A Problem B Problem D Problem F Problem L 考虑二分答案. 设当前待验证的答案为x 我们可以把第二 ...
- 2017 CCPC秦皇岛 M题 Safest Buildings
PUBG is a multiplayer online battle royale video game. In the game, up to one hundred players parach ...
- 2017 CCPC秦皇岛 L题 One Dimensions Dave
BaoBao is trapped in a one-dimensional maze consisting of grids arranged in a row! The grids are nu ...
- 2017 CCPC秦皇岛 H题 Prime set
Given an array of integers , we say a set is a prime set of the given array, if and is prime. Ba ...
- 2017 CCPC秦皇岛 G题 Numbers
DreamGrid has a nonnegative integer . He would like to divide into nonnegative integers and minimi ...
- 2018 CCPC秦皇岛 C题 Crusader Quest
Crusaders Quest is an interesting mobile game. A mysterious witch has brought great darkness to the ...
- 2018年9月28日CCPC秦皇岛站参赛总结
day1: 被中间结果超出int范围给叉了,立刻意识到了自己的弱小以及校赛出题的时候是怎么叉别人的 day2: 签到签了40分钟,谨慎一些还是很好的,机子重启耽误了一些时间 一道暴力+LCS的简单题被 ...
随机推荐
- bzoj 2809 左偏树\平衡树启发式合并
首先我们对于一颗树,要选取最多的节点使得代价和不超过m,那么我们可以对于每一个节点维护一个平衡树,平衡树维护代价以及代价的和,那么我们可以在logn的时间内求出这个子树最多选取的节点数,然后对于一个节 ...
- 原生ES-Module在浏览器中的尝试
其实浏览器原生模块相关的支持也已经出了一两年了(我第一次知道这个事情实在2016年下半年的时候) 可以抛开webpack直接使用import之类的语法 但因为算是一个比较新的东西,所以现在基本只能自己 ...
- ie6下双边距的问题
1.ie6双边距情况 <div class="red"></div> <div class="blue"></div& ...
- 单从软件层面来说,Maya 和 Blender 差别在哪?
单从软件层面来说,Maya 和 Blender 差别在哪? https://www.zhihu.com/question/21975571
- 如何设置static tableview的section区域高度
重写代理方法- (CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { i ...
- ubuntu在vim编辑时,方向键无法正常使用
/* 如果在普通用户下. */ [frankie@localhost ~]$ sudo apt-get install vim [frankie@localhost ~]$ cd /etc/vim [ ...
- iframe弹出框js ie6下存在bug
ie6的iframe在第一次加载的显示不出来,显示空白,但是很奇怪,刷新就可以正常显示了,一开始以为这只是IE6下iframe加载的bug,但是最后结果发现这是ie6下javascript延迟加载出现 ...
- jequry_rotate.js用来写旋转类的东西的插件(如:抽奖转盘)
网上发现一个很有意思的jQuery旋转插件,支持Internet Explorer 6.0+ .Firefox 2.0 .Safari 3 .Opera 9 .Google Chrome,高级浏览器下 ...
- Name Disambiguation in AMiner-Clustering, Maintenance, and Human in the Loop
Name Disambiguation in AMiner: Clustering, Maintenance, and Human in the Loop paper:http://keg.cs.ts ...
- ES6 promise简单实现
基本功能实现: function Promise(fn){ //需要一个成功时的回调 var doneCallback; //一个实例的方法,用来注册异步事件 this.then = function ...