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)被点的次数. 分析: 由于点名有循环,故可先判断出每一个循环每 ...
随机推荐
- 熊猫猪新系统測试之二:Mac OS X 10.10 优胜美地
在第一篇windows 10技术预览版測试之后.本猫为大家呈现还有一个刚刚才更新的mac操作系统:"优胜美地".苹果相同一改以猫科动物为代号命名的传统.在10.9的Maverick ...
- Java注释中的@deprecated与源代码中的@Deprecated
用 @Deprecated注释的程序元素,不鼓励程序员使用这样的元素,通常是因为它很危险或存在更好的选择.在使用不被赞成的程序元素或在不被赞成的代码中执行重写时,编译器会发出警告. 其次,请注意标题, ...
- C++第9周(春)项目5 - 一元一次方程类
课程首页在:http://blog.csdn.net/sxhelijian/article/details/11890759,内有完整教学方案及资源链接 [项目5]设计一元一次方程类.求形如ax+b= ...
- python 深浅复制与指针内存
Python是一门非常好的语言,他的长处在于拥有巨大灵活性的同一时候也拥有无比的严谨性,其它语言规定了非常多语法.告诉你什么情况下,语法就是这种,而Python却用非常少的规定,延伸出非常多语法,有些 ...
- WAMP的端口修改
wamp集成了开源的利器mysql+apache+php,真的是有越来越火的趋势了,可是有些人,安装php的集成开发环境WAMP的时候,出现端口被占用了,无法连接服务器的时候, 这时,如果要修改WAM ...
- Codeforces Beta Round #22 (Div. 2 Only) E. Scheme dfs贪心
E. Scheme To learn as soon as possible the latest news about their favourite fundamentally new ope ...
- javascript来实现详细时间提醒信息效果
我们经常在社交网络上面看到很人性化的时间提示比如,你的朋友几分钟前更新了什么,你的朋友几天前更新了什么信息. 这些小tips比直接显示某年某月人性化很多.我们可以用不同的程序实现这种效果.中国音效网下 ...
- Masonry基本用法
使用步骤: 1.导入框架 2.导入头文件,或者直接导入.pch文件中 //省略前缀 'max_'的宏: #define MAS_SHORTHAND // 自动装箱:自动把基本数据类型转化成对象,int ...
- 转载:百为STM32开发板教程之十二——NAND FLASH
http://bbs.21ic.com/icview-586200-1-1.html 百为STM32开发板教程之十二——NAND FLASH 参考资料:百为stm32开发板光盘V3\百为stm32开发 ...
- 关于centOS7的一些笔记
使用systemctl查看 开启 关闭服务: 查看: systemctl status arcgis.server 开启: systemctl start arcgis.server 关闭: syst ...