http://codeforces.com/contest/758/problem/C

需要一个能够找到任意一个位置的步数的方法,就能解决三个问题。

预处理出one(row, col)表示第一次经过这个点,需要的步数。

sec(row, col),thr(row, col)分别是第二、三步。

那么,循环节就会产生,记录步数为X, Y, Z,那么,第一二步的差距,和第二三步的差距,分别代表了从下走上去和从上走下来。

那么第4次,就会和第一二步的差距相等

就比如是5、17、23,那么下一步就是35.

但是预处理这个one\sec\thr也特别多细节。

然后就可以用循环节了,5 + 每18个增加两次,还要特判下剩余的再够一次。

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <assert.h>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL; #include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <bitset>
int n, m, x, y;
LL tk;
int one(int row, int col) {
return (row - ) * m + col;
}
int sec(int row, int col) {
if (row == n) {
return n * m + (n - ) * m + col + (max(, n - ) * m);
} else if (row == ) {
return n * m + max(, (n - )) * m + col;
}
return one(row, col) + m - col + (n - row) * m + max((n - - row), ) * m + col;
}
int thr(int row, int col) {
if (row == ) {
if (n == ) {
return m * + col;
}
return n * m + (n - ) * m * + m * (max(, n - )) + col;
} else if (row == n) {
return n * m + (n - ) * m * + max(, (n - )) * m + col;
}
return sec(row, col) + (row - ) * m + (row - ) * m + m;
}
LL tofind(int row, int col) {
LL k = tk;
if (k <= one(row, col)) return k >= one(row, col);
k -= one(row, col);
int cir = thr(row, col) - one(row, col);
LL ans = 1LL + (k / cir) * ;
ans += k % cir >= sec(row, col) - one(row, col);
return ans;
}
void work() {
cin >> n >> m >> tk >> x >> y;
// cout << one(x, y) << " " << sec(x, y) << " " << thr(x, y) << endl;
LL ansmx = -, ansmi = 1e18L;
for (int i = ; i <= n; ++i) {
for (int j = ; j <= m; ++j) {
ansmx = max(ansmx, tofind(i, j));
ansmi = min(ansmi, tofind(i, j));
}
}
cout << ansmx << " " << ansmi << " " << tofind(x, y) << endl;
} int main() {
#ifdef local
freopen("data.txt", "r", stdin);
// freopen("data.txt", "w", stdout);
#endif
work();
return ;
}

C. Unfair Poll 数学题,的更多相关文章

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

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

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

  4. CodeForces 758 C Unfair Poll

    Unfair Poll 题意:一共有n排同学每排同学有m个人, 老师问问题有一个顺序, 先从第一排开始问,问完第一排的所有同学之后,再问第2排的,对于所有排的访问顺序为 1,2,3……n-1,n,n- ...

  5. C. Unfair Poll

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

  6. CF758C Unfair Poll

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

  7. 【codeforces 758C】Unfair Poll

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

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

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

  9. CodeFroces 758C - Unfair Poll

    题意: 老师点名,顺序是1 -- n -- 1 排为一个循环,每列为1 -- m的顺序, 问点到最多次数和最少次数的人的次数以及(x,y)被点的次数. 分析: 由于点名有循环,故可先判断出每一个循环每 ...

随机推荐

  1. hdu1507——Uncle Tom&#39;s Inherited Land*

    Uncle Tom's Inherited Land* Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (J ...

  2. 图像处理之基础---opencv 开发的环境搭建

    vs2010 opencv2.4.8 下载: vs2010 http://opencv.org/ 步骤: http://my.phirobot.com/blog/2014-02-opencv_conf ...

  3. 搭建集群后再namenode上查看进程发现除了三个基本进程还可能有别的进程,例如本来在子节点出现的进程出现在了主节点上

    搭建集群后再namenode上查看进程发现除了三个基本进程还可能有别的进程,例如本来在子节点出现的进程出现在了主节点上,namenode按正常来说是有三个进程的:namenode,resourcema ...

  4. 阐述Linux操作系统之rpm五种基本操作

    Linux操作系统现在已经成为流行的操作系统,很多的人都开始学习,Linux操作系统包括了很多的专业知识,今天和大家讲讲Linux操作系统中的rpm基本操作.希望你学会本文中提到rpm的五种基本操作知 ...

  5. ubuntu字符界面下显示中文和调整分辨率

    1.sudo apt-get install zhcon 2.vi /etc/zhcon.conf  修改下面两行 x_resolution 1024 y_resolution 768 完成这两步后在 ...

  6. Struts 1 Struts 2

    Key Technologies Primer https://struts.apache.org/primer.html Threads With Struts 1 you were require ...

  7. (1)iOS9完美越狱

    方式一:同步推越狱,其实用的也是方式二 参考:iOS9.3.5不完美越狱(点击跳转) 方式二:使用impactor越狱. 下载地址:http://www.pc6.com/mac/505285.html

  8. YTU 2903: A--A Repeating Characters

    2903: A--A Repeating Characters 时间限制: 1 Sec  内存限制: 128 MB 提交: 50  解决: 30 题目描述 For this problem,you w ...

  9. HTML与JSP页面的区别

    HTML(Hypertext Markup Language)文本标记语言,它是静态页面,和JavaScript一样解释性语言,为什么说是解释性 语言呢?因为,只要你有一个浏览器那么它就可以正常显示出 ...

  10. 字符串输出输入函数,const修饰符,内存分区,动态内存管理,指针和函数,结构体

    1.字符串输出输入函数 读入字符串的方法: 1) scanf 特点:不能接收空格 2) gets 特点:可以接受含有空格的字符串 ,不安全 3) fgets(); 特点:可以帮我们自动根据数组的长度截 ...