Codeforces 758C Unfair Poll
2017-01-20 14:08
232 查看
题目链接:http://codeforces.com/contest/758/problem/C
题意:不公平的点名,给定一个教室,然后老师按照一定规则点名,行数从1点到n,再回到 1,列数一直从1到m 。求点名最多的学生的次数,和最少的,和一定位置的点名次数。
分析:
不太擅长计数,直接模拟一个二维矩阵好了,由于从前往后和从后往前是不一样的,直接建一个数组记录从前往后+从后往前,其中数据类型为pair<int ,int> 型。
题意:不公平的点名,给定一个教室,然后老师按照一定规则点名,行数从1点到n,再回到 1,列数一直从1到m 。求点名最多的学生的次数,和最少的,和一定位置的点名次数。
分析:
不太擅长计数,直接模拟一个二维矩阵好了,由于从前往后和从后往前是不一样的,直接建一个数组记录从前往后+从后往前,其中数据类型为pair<int ,int> 型。
#include <bits/stdc++.h> using namespace std; long long a[110][110]; vector<pair<int,int> > V; int main() { int n,m,x,y; unsigned long long k; cin>>n>>m>>k>>x>>y; if(n==1) { for(int i=0; i<m; i++) { V.push_back(make_pair(1,i+1)); } } else { for(int i=0; i<n; i++) { for(int j=0; j<m; j++) { V.push_back(make_pair(i+1,j+1)); } } for(int i=n-1; i>1; i--) { for(int j=0; j<m; j++) V.push_back(make_pair(i,j+1)); } } int T = V.size(); unsigned long long p = k / T; for(int i=0; i<T; i++) { a[V[i].first][V[i].second] +=p; } k = k%T; for(unsigned long long i=0; i<k; i++) { a[V[i].first][V[i].second]++; } long long mn = 1LL << 60, mx = 0; 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; }
相关文章推荐
- 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