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的更多相关文章

  1. 【codeforces 758C】Unfair Poll

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  2. Codeforces 758C:Unfair Poll(思维+模拟)

    http://codeforces.com/problemset/problem/758/C 题意:教室里有n列m排,老师上课点名从第一列第一排开始往后点,直到点到第一列第m排,就从第二列第一排开始点 ...

  3. Codeforces 392 C Unfair Poll(模拟)

    题意:老师点名顺序规则如下:第1排,第2排,……,第n-1排,第n排,第n-1排,……,第2排,第1排,第2排,……,第n-1排,第n排,……对于每排都是从左到右依次点名,问点名k个人后,所有人中最多 ...

  4. 【找规律】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 ...

  5. 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 ...

  6. C. Unfair Poll

    http://codeforces.com/problemset/problem/758/C C. Unfair Poll time limit per test 1 second memory li ...

  7. 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 ...

  8. C. Unfair Poll 数学题,

    http://codeforces.com/contest/758/problem/C 需要一个能够找到任意一个位置的步数的方法,就能解决三个问题. 预处理出one(row, col)表示第一次经过这 ...

  9. CF758C Unfair Poll

    题意: On the Literature lesson Sergei noticed an awful injustice, it seems that some students are aske ...

随机推荐

  1. 01-Spring Security框架学习

    目录 01-Spring Security框架学习 简介 Spring Security 是什么 Spring Security 解决那些问题 Spring Security 的优点 历史背景 Spr ...

  2. win10和浏览器快捷键

    1. Win10快捷键[Win+↑/↓/←/→] 将当前窗口按比例固定到屏幕的四个边角,如左上.右上.左下.右下.[Win+1/2/3…] 按顺序打开任务栏上的已固定程序(不包括第一个“任务视图”按钮 ...

  3. 数据结构之队列C++版

    #include "stdafx.h"/* 队列是一种先进先出的线性表队列的核心是对头部和尾部索引的操作 如上图所示,当对头索引移动到最前面6,队尾又不不再末尾0的位置,那么如果不 ...

  4. Opengl_入门学习分享和记录_02_渲染管线(一)顶点着色器&片段着色器

    写在前面的废话:今天俺又来了哈哈,真的好棒棒! 今天的内容:之前我们大概描述了,我们自己定义的顶点坐标是如何被加载到GPU之中,并且介绍了顶点缓冲对象VBO用于管理这一块内存.今天开始详细分析它的具体 ...

  5. JVM调优前戏之JDK命令行工具---jhat

    在JDK的命令行中,一般开发人员最耳熟能详的肯定就是java,javac,javap等常用命令,不过在jdk/bin下还有许多其他的命令行工具,它们被用来监测JVM运行时的状态,下面我们来详细解读一下 ...

  6. BFS-迷宫问题

    问题描述 定义一个二维数组: int maze[5][5] = { 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, ...

  7. nginx 使用HTTPS协议-SSL证书模块报错解决-附nginx安装 : [emerg] the "ssl" parameter requires ngx_http_ssl_module in nginx.c

    Linux系统下ngnix使用HTTPS协议启动报错: nginx: [emerg] the "ssl" parameter requires ngx_http_ssl_modul ...

  8. 访问CGI程序时不添加 /cgi-bin/ 目录也可访问

    配置如下 <VirtualHost *:80> DocumentRoot D:\web_root\test ServerName www.test.com <Directory /& ...

  9. 帝国CMS(EmpireCMS) v7.5 后台XSS漏洞分析

    帝国CMS(EmpireCMS) v7.5 后台XSS漏洞分析 一.漏洞描述 该漏洞是由于代码只使用htmlspecialchars进行实体编码过滤,而且参数用的是ENT_QUOTES(编码双引号和单 ...

  10. MinorGC 和 FullGC的理解

    1.GC回收机制熟悉么,分代算法知道么?2.了解 Java 虚拟机的垃圾回收算法? 从年轻代空间(包括 Eden 和 Survivor 区域)回收内存被称为 Minor GC. Major GC 是清 ...