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. 谈一谈关于NODE里的N管理

    模块可能与当前的NODE版本不和,NODE升级问题? 一切尽在掌握 1.首先设置好PATH(你安装的目录) Debian系列: sudo gedit /etc/profile Redhat系列: su ...

  2. Codeforces Round #221 (Div. 2) D

    有点郁闷的题目,给了2000ms,可是n,m的范围已经是5000了.5000 * 5000一般在别的OJ已经是超了2000ms,一開始不敢敲.看了下别人有n*m的潜逃循环,原来CF的机子如此的强大,一 ...

  3. python的线程thread笔记

    python的线程是用thread和threading来实现的.其中利用threading会更好,因为thread没有线程保护,当主线程退出了之后,子线程也会被强行退出.threading支持守护线程 ...

  4. C#&.NET高级面试题

    转自http://chaoyouzhuo.blog.163.com/blog/static/1263760012011109114131316/ 1. DateTime.Parse(myString) ...

  5. js实现replaceAll功能

    js中没有原生的replaceAll 方法. function replaceAll(str , replaceKey , replaceVal){ var reg = new RegExp(repl ...

  6. iOS开发——高级篇——iOS涂鸦画板效果实现

    一个简单的绘图应用,模仿苹果自带软件备忘录里的涂鸦功能 核心代码 #import "DrawView.h" #import "DrawPath.h" @inte ...

  7. Error CREATEing SolrCore 'new_core': Unable to create core [new_core] Caused by: Can't find resource 'solrconfig.xml' in classpath or 'D:\solr\solr-7.2.1\server\solr\new_core'

    \solr-7.2.1\server\solr\configsets\_default  下的conf  复制到:   \solr-7.2.1\server\solr\new_core

  8. mac系统怎么给文件夹加密?mac文件夹加密教程

    mac系统怎么给文件夹加密?目前来说,若想要对你的Mac OS下面的文件进行加密的话有三种方法可以可以做到,第一种方法,Mac自带磁盘工具:第二种方法,例如BatterZip此类Mac压缩解压工具打包 ...

  9. ios app 上架AppStore

    一.证书的导出      1.1 前期工作        首先你需要有一个苹果的开发者帐号,一个Mac系统.        如果没有帐号可以在打开http://developer.apple.com/ ...

  10. 四:多线程--NSOperation简单介绍

    一.NSOperation简介 1.NSOperation的作⽤:配合使用NSOperation和NSOperationQueue也能实现多线程编程 NSOperation和NSOperationQu ...