Codeforces 758C. Unfair Poll
2017-01-29 20:52
232 查看
题目大意:
在一个\(n*m\)的棋盘上连续进行k次操作,每次操作会把格子里的数+1,初始为零.操作的顺序见题解.问最大值,最小值以及某一格子上的数。\(n,m\leq100,k\leq10^{18}\)
题解:
由于操作的时候对于行是:\(1,2,3,..,n,n-1,n-2,...,1,2,3,...\)
对于列是:\(1,2,3,...,n,1,2,3,...\)
所以我们把\(1..n..2\)视作一个周期,把\(k\)取模即可.
注:注意n = 1的情况
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; typedef unsigned long long ll; template<typename T>inline void read(T &x){ x=0;char ch;bool flag = false; while(ch=getchar(),ch<'!');if(ch == '-') ch=getchar(),flag = true; while(x=10*x+ch-'0',ch=getchar(),ch>'!');if(flag) x=-x; } template<typename T>inline T cat_max(const T &a,const T &b){return a>b ? a:b;} template<typename T>inline T cat_min(const T &a,const T &b){return a<b ? a:b;} const ll maxn = 1024; ll a[maxn][maxn]; int main(){ ll n,m,x,y,k,mod,base; read(n);read(m);read(k);read(x);read(y); if(n == 1) mod = m; else mod = (2*n-2)*m; base = k/mod;k%=mod; // printf("%I64d %I64d\n",k,base); for(ll i=1;i<=m;++i) a[1][i] = base,a [i] = base; for(ll i=2;i<n;++i){ for(ll j=1;j<=m;++j){ a[i][j] = base<<1LL; } } for(ll i=1;i<=n && k;++i){ for(ll j=1;j<=m && k;++j){ --k; a[i][j]++; } } for(ll i=n-1;i>=2 && k;--i){ for(ll j=1;j<=m && k;++j){ --k; a[i][j]++; } } ll ans1 = 0,ans2 = 1LL<<60; for(ll i=1;i<=n;++i){ for(ll j=1;j<=m;++j){ // printf("%I64d ",a[i][j]); ans1 = cat_max(ans1,a[i][j]); ans2 = cat_min(ans2,a[i][j]); }//puts(""); } printf("%I64d %I64d %I64d\n",ans1,ans2,a[x][y]); getchar();getchar(); return 0; }
相关文章推荐
- CodeForces 24C Sequence of points (几何)
- Codeforces 347C Alice and Bob
- CodeForces 591B
- Codeforces 344E - Read Time
- CodeForces - 622E dfs+贪心
- [CodeForces-721E]Road to Home
- CodeForces 245D Restoring Table
- Codeforces 460C Present (贪心 + 二分)
- 【CodeForces】[621A]Wet Shark and Odd and Even
- 素数筛-CodeForces 327B Hungry Sequence
- [线段树] Codeforces 794F Round #414 F. Leha and security system
- Codeforces 284E Coin Troubles【思维+拓扑排序+完全背包】好题!
- CodeForces 401C
- codeforces 414B B. Mashmokh and ACM(dp)
- codeforces 354 div2 C Vasya and String 前缀和
- Codeforces 733D Kostya the Sculptor 贪心
- Codeforces 104C Cthulhu dfs暴力 || 点双连通缩点
- CodeForces 867A Between the Offices
- Codeforces 413C Jeopardy!(贪心)
- CodeForces 425E Sereja and Sets