CodeForces 758 C Unfair Poll
题意:一共有n排同学每排同学有m个人, 老师问问题有一个顺序, 先从第一排开始问,问完第一排的所有同学之后,再问第2排的,对于所有排的访问顺序为 1,2,3……n-1,n,n-1,n-2,……,2,1,2,然后每次访问到新的一排先要问完这一排的所有人才会往下一(目标)排走。
题解:先声明我们开一个数组来记录这一排被询问的总次数,先将k /= m, 这个代表的是完全访问的次数,即一整排m位同学都问完有几次,如果 完全访问的次数< n, 我们就将前几排全访问次数的人都加上m,并且将剩下的访问次数都塞到一下排就好了,如果完全访问次数大于n了之后,发现除了第一次转移的次数位n-1排, 我们再对 k/=(n-1) 处理出来, 然后判断奇偶性来决定最后一次是从上到下还是从下到上,对于所有的排都加上次数,最后再把刚开始的访问次数塞到目标排就好了。
n==1的话,对于上述解法要特殊讨论因为除数或者模数不能为0。
代码:
#include<bits/stdc++.h>
using namespace std;
#define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout);
#define LL long long
#define ULL unsigned LL
#define fi first
#define se second
#define pb push_back
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const LL mod = (int)1e9+;
const int N = 2e5 + ;
LL n, m, x, y;
LL k, ans1, ans2 = INF, ans3;
LL cnt[N];
int main(){
scanf("%I64d%I64d%I64d%I64d%I64d", &n, &m, &k, &x, &y);
LL c1, c2;
c1 = k/m;
c2 = k%m;
swap(c1, k);
if(k < n){
for(int i = ; i <= k; i++) cnt[i] = m;
cnt[k+] = c2;
}
else {
for(int i = ; i <= n; i++) cnt[i] = m;
k -= n;
if(n != ){
LL t = n-;
LL z = k / t;
LL lf = k % t;
LL t1 = z-z/;
for(int i = ; i < n; i++) cnt[i] += t1*m;
for(int i = ; i <= n; i++) cnt[i] += z/ * m;
if(z&1ll){
int g = ;
for(int i = ; i <= n, lf > ; i++, lf--) cnt[i] += m, g = i;
cnt[++g] += c2;
}
else{
int g = n;
for(int i = n-; i >= , lf > ; i--, lf--) cnt[i] += m, g = i;
cnt[--g] += c2;
}
}
else cnt[] = c1;
}
for(int i = ; i <= n; i++){
if(cnt[i] == ) {ans2 = ; continue;}
if(i == x) {
LL lf = cnt[i]%m;
ans3 = cnt[i]/m;
if(lf >= y) ans3++;
};
LL t1 = cnt[i]/m;
if(cnt[i]%m) t1++;
ans1 = max(ans1, t1);
LL t2 = cnt[i]/m;
ans2 = min(ans2, t2);
} printf("%I64d %I64d %I64d", ans1, ans2, ans3);
return ;
}
758 C
CodeForces 758 C Unfair Poll的更多相关文章
- 【codeforces 758C】Unfair Poll
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- Codeforces 758C:Unfair Poll(思维+模拟)
http://codeforces.com/problemset/problem/758/C 题意:教室里有n列m排,老师上课点名从第一列第一排开始往后点,直到点到第一列第m排,就从第二列第一排开始点 ...
- Codeforces 392 C Unfair Poll(模拟)
题意:老师点名顺序规则如下:第1排,第2排,……,第n-1排,第n排,第n-1排,……,第2排,第1排,第2排,……,第n-1排,第n排,……对于每排都是从左到右依次点名,问点名k个人后,所有人中最多 ...
- 【找规律】Codeforces Round #392 (Div. 2) C. Unfair Poll
C. Unfair Poll time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- Codeforces Round #392 (Div. 2) Unfair Poll
C. Unfair Poll time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- C. Unfair Poll
http://codeforces.com/problemset/problem/758/C C. Unfair Poll time limit per test 1 second memory li ...
- Codeforces758C Unfair Poll 2017-01-20 10:24 95人阅读 评论(0) 收藏
C. Unfair Poll time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- C. Unfair Poll 数学题,
http://codeforces.com/contest/758/problem/C 需要一个能够找到任意一个位置的步数的方法,就能解决三个问题. 预处理出one(row, col)表示第一次经过这 ...
- CF758C Unfair Poll
题意: On the Literature lesson Sergei noticed an awful injustice, it seems that some students are aske ...
随机推荐
- Currency Exchange POJ1860
Description Several currency exchange points are working in our city. Let us suppose that each point ...
- 新IT运维时代 | Docker运维之最佳实践-下篇
上篇针对操作系统.主机配置.容器镜像.容器运行时四大方面分享一些Docker的运维经验,本篇将着重在Docker Daemon参数和权限两个方面进一步分享.(阅读上篇请点击右侧:新IT运维时代 | D ...
- Zabbix-agentd错误整理
一.无法启动 (一).当时环境 Firewalld与Selinux,Iptables都为关闭 配置环境 OS:CentOS Zabbix-server IP:10.18.43.71 Hostname: ...
- 【Java笔记】【Java核心技术卷1】chapter3 D2注释
package chapter3; /** * 文档注释 *@author lp *@version 1 **/ public class D2注释 { //单行注释 /* 长注释 */ }
- JVM系列(1)- JVM常见参数及堆内存分配
常见参数配置 基于JDK1.6 -XX:+PrintGC 每次触发GC的时候打印相关日志 -XX:+UseSerialGC 串行回收模式 -XX:+PrintGCDetails 打印更详细的GC日志 ...
- ASP.NET Core MVC 之控制器(Controller)
操作(action)和操作结果(action result)是 ASP.NET MVC 构建应用程序的一个基础部分. 在 ASP.NET MVC 中,控制器用于定义和聚合一组操作.操作是控制器中处理传 ...
- java多线程基础(一)--sleep和wait的区别
sleep和wait的区别有: 1.这两个方法来自不同的类分别是Thread和Object: 2.最主要是sleep方法没有释放锁,而wait方法释放了锁,使得线程可以使用同步控制块或者方法: 3.w ...
- 浅谈微服务架构与服务治理的Eureka和Dubbo
前言 本来计划周五+周末三天自驾游,谁知人算不如天算,周六恰逢台风来袭,湖州附近的景点全部关停,不得已只能周五玩完之后,于周六踩着台风的边缘逃回上海.周末过得如此艰难,这次就聊点务虚的话题,一是浅谈微 ...
- strstr函数使用中的一个错误解决
最近使用ESP8266的时候,联网的过程中需要使用strstr函数来读取串口发来的某些重要信息, 使用strstr函数发现某些时候能够正常返回需要寻找的字符串的指针,有些时候找不到,后来发现原来是这样 ...
- struts的上传下载
文件上传 添加jar包 commons-io-1.3.2.jar commons-fileupload-1.2.1.jar 前台页面 form表单 method值为post 添加"encty ...