题目链接:http://codeforces.com/contest/758/problem/C
题目大意:
有 n 行,每行有 m 个学生,老师首先从(1,1)开始叫,一直叫到(n,m),再叫到(1,1),以此类推,问最后,被老师叫到次数最多的那个次数,叫到次数最小的那个次数,一个人被叫到的次数(这人的坐标是(x,y))。
题解:
本题是一个不错的题目,很锻炼思维(小心被 hack)。对 1 的情况特判,然后模拟老师的叫法。注意 k 很大,需要先找出循环,即 n*m+(n-2)*m 一循环。然后处理余数(k%(n*m+(n-2)*m)的余数)即可,注意细节!!
题目代码:
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;
LL n, m, k, x, y;
const int size = 1e2+5;
const LL inf = 1LL << 60;
LL a[size][size];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m >> k >> x >> y;
if( n == 1 ) {
LL temp = k/m;
if(k%m) cout << temp+1 << " ";
else cout << temp << " ";
cout << temp << " " ;
if(k%m >= y) cout << temp+1;
else cout << temp;
cout << endl;
return 0;
}
LL loop = n*m+(n-2)*m;
LL lst = k%loop;
LL get = k/loop;
for ( int i = 1; i <= n; i ++ ) {
for ( int j = 1; j <= m; j++ ) {
if( i == 1 || i == n ) a[i][j] += get;
else a[i][j] += get*2;
}
}
int i, j, p; i = j = 1;
while( lst > 0 ) {
a[i][j] ++;
j ++;
if( j > m ) {
j = 1;
if(i == n) p = -1;
else if( i == 1 ) p = 1;
i += p;
}
lst --;
}
LL mx = -1, mn = inf;
for ( int i = 1; i <= n; i++ ) {
for ( int j = 1; j <= m; j++ ) {
mn = min(mn, a[i][j]);
mx = max(mx, a[i][j]);
}
}
cout << mx << " " << mn << " " << a[x][y] << endl;
return 0;
}