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的简单题被 ...
 
随机推荐
- 牛客网刷题(纯java题型 31~60题)
			
牛客网刷题(纯java题型 31~60题) 重写Override应该满足"三同一大一小"三同:方法名相同,参数列表相同,返回值相同或者子类的返回值是父类的子类(这一点是经过验证的) ...
 - java===java基础学习(3)---数据类型转换,运算符级别,枚举类型
			
数据类型转换: 有的时候,程序需要将数据类型,比如 int + float ,结果是float, 这里的int就被转换为float类型,属于合法转换. Java中的合法转换如下图: 红色表示无信息丢失 ...
 - python实战===itchat
			
import itchat itchat.login() friends=itchat.get_friends(update=True)[0:] male=female=other=0 for i i ...
 - 判断cookie创建的时间是否已经24小时
			
def read_cookie(self): cookiesfilepath="cookies%s" % self.uid if os.path.exists(cookiesfil ...
 - 设计模式之笔记--单例模式(Singleton)
			
单例模式(Singleton) 定义 单例模式(Singleton),保证一个类仅有一个实例,并提供一个访问它的全局访问点. 类图 描述 类Singleton的构造函数的修饰符为private,防止用 ...
 - [hadoop][基本原理]zookeeper简单使用
			
代码:https://github.com/xufeng79x/ZkClientTest 1.简介 zookeeper的基本原理和使用场景描述可参考:[hadoop][基本原理]zookeeper基本 ...
 - 使用while循环遍历文件
			
/* 使用while循环遍历文件*/ [root@localhost test1]# vim 17.py //add #!/usr/bin/python ll = open('/tmp/1.txt') ...
 - Go语言大神亲述:历七劫方可成为程序员!
			
“历劫1”:你坚信你可以用Go来做面向对象编程? 在经历了一次Go应用之旅之后,你可能就会开始思考:“怎么样才能让这种语言更像面向对象的编程语言?”因为你已经习惯了这种编程,你想要制作健壮的代码.想要 ...
 - windows下github 出现Permission denied (publickey)
			
github教科书传送门:http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000 再学习到 ...
 - VS的使用
			
配置一个工程 问题描述: 要运行一个源码工程,工程中含有层级目录,.cpp与.h在多级目录中混合存储.并且该工程的运行依赖一些静态库(.lib)与动态库(.dll). 建立: 把.h拷贝至$(Proj ...