C. Unfair Poll 数学题,
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 数学题,的更多相关文章
- 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 ...
- 【找规律】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 ...
- CodeForces 758 C Unfair Poll
Unfair Poll 题意:一共有n排同学每排同学有m个人, 老师问问题有一个顺序, 先从第一排开始问,问完第一排的所有同学之后,再问第2排的,对于所有排的访问顺序为 1,2,3……n-1,n,n- ...
- C. Unfair Poll
http://codeforces.com/problemset/problem/758/C C. Unfair Poll time limit per test 1 second memory li ...
- CF758C Unfair Poll
题意: On the Literature lesson Sergei noticed an awful injustice, it seems that some students are aske ...
- 【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排,就从第二列第一排开始点 ...
- CodeFroces 758C - Unfair Poll
题意: 老师点名,顺序是1 -- n -- 1 排为一个循环,每列为1 -- m的顺序, 问点到最多次数和最少次数的人的次数以及(x,y)被点的次数. 分析: 由于点名有循环,故可先判断出每一个循环每 ...
随机推荐
- 同步定制 Unity团队 程序的C#文件模板
孙广东 2015.7.30 就是把程序制定好的模板(不论什么人能够更改并同步git)放到,unity项目的Editor 目录下, 当程序新建一个C#脚本后就是这个模板了. "81-C# ...
- 【转载】C# 装箱和拆箱[整理]
1. 装箱和拆箱是一个抽象的概念 2. 装箱是将值类型转换为引用类型 :拆箱是将引用类型转换为值类型 利用装箱和拆箱功能,可通过允许值类型的任何值与Object 类型的 ...
- linux 【第五篇】特殊权限及定时任务
特殊权限 [root@VM_141_154_centos ~]# ls -ld /tmp drwxrwxrwt. 8 root root 4096 Apr 5 08:11 /tmp /tmp/ 公共目 ...
- 关于OutOfMemoryError的处理
转自:http://www.blogjava.net/rosen/archive/2010/05/21/321575.html http://www.blogjava.net/rosen/archiv ...
- 查看android-support-v4.jar引出的问题
1.前面博文里也写过如何关联android-support-v4.jar的源码 今天新项目用上述方法的时候,竟然不成功..来回反复试了很长时间,最后发现 新建项目,会自动引用一个类库(自动新建的..) ...
- linux系统编程之进程(七):system()函数使用【转】
本文转载自:http://www.cnblogs.com/mickole/p/3187974.html 一,system()理解 功能:system()函数调用“/bin/sh -c command” ...
- YTU 2958: 代码填充--雨昕学画画
2958: 代码填充--雨昕学画画 时间限制: 1 Sec 内存限制: 128 MB 提交: 156 解决: 102 题目描述 雨昕开始学画水彩画,老师给雨昕一个形状(Shape)类,雨昕在Sha ...
- YTU 2914: xiaoping学构造函数
2914: xiaoping学构造函数 时间限制: 1 Sec 内存限制: 128 MB 提交: 148 解决: 90 题目描述 xiaoping刚接触类的构造和析构函数,对于构造函数的编写比较困 ...
- C#函数3递归
using System;using System.Collections.Generic;using System.Linq;using System.Text; namespace Console ...
- I.MX6 i2c_data_write_byte ioctl error: I/O error
/************************************************************************* * I.MX6 i2c_data_write_by ...