2017 CCPC秦皇岛 A题 A Ballon Robot
The 2017 China Collegiate Programming Contest Qinhuangdao Site is coming! There will be teams participating in the contest, and the contest will be held on a huge round table with seats numbered from 1 to in clockwise order around it. The -th team will be seated on the -th seat.
BaoBao, an enthusiast for competitive programming, has made predictions of the contest result before the contest. Each prediction is in the form of , which means the -th team solves a problem during the -th time unit.
As we know, when a team solves a problem, a balloon will be rewarded to that team. The participants will be unhappy if the balloons take almost centuries to come. If a team solves a problem during the -th time unit, and the balloon is sent to them during the -th time unit, then the unhappiness of the team will increase by . In order to give out balloons timely, the organizers of the contest have bought a balloon robot.
At the beginning of the contest (that is to say, at the beginning of the 1st time unit), the robot will be put on the -th seat and begin to move around the table. If the robot moves past a team which has won themselves some balloons after the robot's last visit, it will give all the balloons they deserve to the team. During each unit of time, the following events will happen in order:
- The robot moves to the next seat. That is to say, if the robot is currently on the -th () seat, it will move to the ()-th seat; If the robot is currently on the -th seat, it will move to the 1st seat.
- The participants solve some problems according to BaoBao's prediction.
- The robot gives out balloons to the team seated on its current position if needed.
BaoBao is interested in minimizing the total unhappiness of all the teams. Your task is to select the starting position of the robot and calculate the minimum total unhappiness of all the teams according to BaoBao's predictions.
Input
There are multiple test cases. The first line of the input contains an integer , indicating the number of test cases. For each test case:
The first line contains three integers , and (, , ), indicating the number of participating teams, the number of seats and the number of predictions.
The second line contains integers (, and for all ), indicating the seat number of each team.
The following lines each contains two integers and (, ), indicating that the -th team solves a problem at time according to BaoBao's predictions.
It is guaranteed that neither the sum of nor the sum of over all test cases will exceed .
<h4< dd="">Output
For each test case output one integer, indicating the minimum total unhappiness of all the teams according to BaoBao's predictions.
<h4< dd="">Sample Input
4
2 3 3
1 2
1 1
2 1
1 4
2 3 5
1 2
1 1
2 1
1 2
1 3
1 4
3 7 5
3 5 7
1 5
2 1
3 3
1 5
2 5
2 100 2
1 51
1 500
2 1000
<h4< dd="">Sample Output
1
4
5
50
<h4< dd="">Hint
For the first sample test case, if we choose the starting position to be the 1st seat, the total unhappiness will be (3-1) + (1-1) + (6-4) = 4. If we choose the 2nd seat, the total unhappiness will be (2-1) + (3-1) + (5-4) = 4. If we choose the 3rd seat, the total unhappiness will be (1-1) + (2-1) + (4-4) = 1. So the answer is 1.
For the second sample test case, if we choose the starting position to be the 1st seat, the total unhappiness will be (3-1) + (1-1) + (3-2) + (3-3) + (6-4) = 5. If we choose the 2nd seat, the total unhappiness will be (2-1) + (3-1) + (2-2) + (5-3) + (5-4) = 6. If we choose the 3rd seat, the total unhappiness will be (1-1) + (2-1) + (4-2) + (4-3) + (4-4) = 4. So the answer is 4.
题意:就是CCPC比赛,有n支队伍,m个座位,n支队伍坐在这些座位上面,一个机器人从任意位置开始每次移动一个位置分发气球,如果到了m,则下一次从新回到第一个位置;每只队伍有一个
愤怒值为过题时间和分发气球的时间差,让你求这些队伍愤怒值和的最小值;
题解:窝萌阔以假设它从1号店开始,算出每次请求的t-b的值并保存在数组h中,值的范围在(0~m-1)之间。若起点向后移动一个则数组h中的数据都加一,且等于M的都变为0。由于M有10的9次方所以不能遍历所有的可能。
参考代码:
#include<bits/stdc++.h>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
typedef long long ll;
const int maxn=1e5+;
int t;
ll n,m,p,x,y,a[maxn],h[maxn];
int main()
{
cin>>t;
while(t--)
{
ll ans=;
cin>>n>>m>>p;
for(int i=;i<=n;i++) cin>>a[i];
for(int i=;i<p;i++)
{
cin>>x>>y;
h[i]=(a[x]-(y%m)+m)%m;
ans+=h[i];
}
ll sum=ans,cp=;
sort(h,h+p);
for(int i=p-;i>=;i--)
{
int temp=;
while(h[i-temp]==h[i]&&i>=temp) temp++;
h[i]+=cp; cp+=m-h[i];
ans+=(p-temp)*(m-h[i]); ans-=temp*h[i];
sum=min(sum,ans);
i-=temp-;
}
cout<<sum<<endl;
}
return ;
}
2017 CCPC秦皇岛 A题 A Ballon Robot的更多相关文章
- 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秦皇岛 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秦皇岛 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 ...
- 2017 ccpc哈尔滨 A题 Palindrome
2017 ccpc哈尔滨 A题 Palindrome 题意: 给一个串\(T\),计算存在多少子串S满足\(S[i]=S[2n−i]=S[2n+i−2](1≤i≤n)\) 思路: 很明显这里的回文串长 ...
- HDU 6268 Master of Subgraph (2017 CCPC 杭州 E题,树分治 + 树上背包)
题目链接 2017 CCPC Hangzhou Problem E 题意 给定一棵树,每个点有一个权值,现在我们可以选一些连通的点,并且把这点选出来的点的权值相加,得到一个和. 求$[1, m] ...
- HDU 6271 Master of Connected Component(2017 CCPC 杭州 H题,树分块 + 并查集的撤销)
题目链接 2017 CCPC Hangzhou Problem H 思路:对树进行分块.把第一棵树分成$\sqrt{n}$块,第二棵树也分成$\sqrt{n}$块. 分块的时候满足每个块是一个 ...
- 2018 CCPC秦皇岛 C题 Crusader Quest
Crusaders Quest is an interesting mobile game. A mysterious witch has brought great darkness to the ...
随机推荐
- Linux下rpm仓库搭建
一.概念 1.rpm是什么?在帮助文档里我们可以看到,rpm的名字是rpm package manage 的缩写, 从名字上看就可以知道rpm就是一个包管理工具.简单说rpm包就是把一些程序编译成二进 ...
- Java基础语法07-面向对象-多态
抽象类 抽象方法 : 没有方法体的方法. 抽象类:被abstract所修饰的类. 抽象类的语法格式: [权限修饰符] abstract class 类名{ }[权限修饰符] abstract clas ...
- 多线程-等待(Wait)和通知(notify)
1.为了支撑多线程之间的协作,JDK提供了两个非常重要的线程接口:等待wait()方法和通知notify()方法. 这两个方法并不是在Thread类中的,而是输出在Object类.这意味着任何对象都可 ...
- 给大家整理了几个开源免费的 Spring Boot + Vue 学习资料
最近抽空在整理前面的文章案例啥的,顺便把手上的几个 Spring Boot + Vue 的学习资料推荐给各位小伙伴.这些案例有知识点的讲解,也有项目实战,正在做这一块的小伙伴们可以收藏下. 案例学习 ...
- vue开发之跨域请求,请求头not allowed by Access-Control-Allow-Headers,后端cookie session值取不到(二)
原因:你本地的请求ajax的get和post请求:如果你的请求头内放一些可用验证数据Token的时候就会存在跨域请求这是浏览器所不允许的问题: 方案一:后台的接口请求模式都写成jsonp请求,前端去调 ...
- 微信web协议,群成员唯一uin,获取群成员唯一标识
群成员唯一标识获取接口 全网最新,支持调试测试.觉得OK再付款! 800元出售源码 不讲价 联系QQ:2052404477
- ArcGIS API For Javascript :如何解决跨网不能正常获取依赖项的问题?
一.前言 政企项目通常会在自组网以及保密网运行,有些单位甚至会有两个物理隔绝的网络存在.通常情况下我们会在两个网络中部署相同的地图服务和依赖项.但是也有其中一个网络密级很高没有服务器资源,不能单独部署 ...
- webpack3、4的基本的使用方法
webpack的基本使用 webpack的安装 webpack的使用时需要借助 node 的环境的 在 node 中自动下载了 npm 这个包管理工具,之后的操作我们需要使用npm包管理工具进行相关操 ...
- React入门知识点清单
做前端的一定都知道现在是三大框架--Vue.React.Angular三足鼎立的时代.Vue是公认的最容易入门的,因为它文件结构上有传统的HTML的影子,让刚接触它的前端人员刚到很"亲切&q ...
- [FPGA]Verilog实现可自定义的倒计时器(24秒为例)
目录 想说的话... 样例_边沿检测计数器 代码讲解 仿真演示 拓展_自定义倒计时数和倒计时间隔 代码讲解 仿真演示 总结 实例_24秒倒计时器 想说的话... 本次实现的是一个24秒倒计时器,功能顾 ...