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)被点的次数. 分析: 由于点名有循环,故可先判断出每一个循环每 ...
随机推荐
- 基于空间直方图meanshift跟踪
近期看了一篇文章<spatiograms versus histograms for region-based tracking>,在此把这篇文章的核心思想及算法推理进行整理. 空间直方图 ...
- ==和equals的差别
== 和 Equals 的差别 1. == 是一个运算符. 2.Equals则是string对象的方法.能够.(点)出来. 我们比較无非就是这两种 1.基本数据类型比較 2.引用对象比較 1.基本数据 ...
- cocos2d-x调用scheduleUpdate()不执行update()方法的解决办法【转】
原文地址:http://blog.csdn.net/somestill/article/details/9699377 前两天使用到每帧都更新动画的scheduleUpdate()方法,但通过cclo ...
- struts2多图片上传实例【转】
原文地址:http://blog.csdn.net/java_cxrs/article/details/6004144 描述: 通过struts2实现多图片上传. 我使用的版本是2.2.1,使用的包有 ...
- NHibernate不支持复杂的linq,就一定要用DataTable这么低级吗
有些linq,好不容易写出来,正想扬眉吐屁一番,不料用NHibernate一执行,却报错,说是不支持,我靠. 只好捏着鼻子写一大段sql,交给它.这种直接执行SQL的情况,我看我同事写的,全部都是返回 ...
- jetty9 web app的部署
jetty9将web app和web app的context配置文件都放在${JETTY_HOME}/webapps下面. 例如,如果有一个myapp.war,首先将其放入${JETTY_HOME}/ ...
- 第一个Java程序示例——Hello World!【转】
本文转载自: 跟随世界潮流,第一个Java程序输出“Hell World!”. 通过Eclipse运行程序 启动Eclipse,在菜单中选择“文件 --> 新建 --> Java项目”,弹 ...
- Basic Queries (LINQ to XML)
https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/linq/basic-queries-linq-to ...
- [USACO 2004DEC] Navigation Nightmare
[题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=3362 [算法] 带权并查集 时间复杂度 : O(NlogN) [代码] #inclu ...
- cocos2d-x-2.1.5版本在Xcode4.2中首次编译ccimage Semantic Issue出错解决方法
// XXX: ios7 casting [str drawInRect:CGRectMake(textOriginX, textOrigingY, textWidth, textHeight) wi ...