Codeforces Round #316 (Div. 2) A. Elections
原题: http://codeforces.com/contest/570/problem/A
题目大意: 竞选问题, n个候选人, m个城市. 选取规则是,第一轮同城选最大,一样选最小index. 第二轮是城市间选最大, 一样选最小index.
分析: 没什么分析的…走一遍矩阵先行找最大, 然后记录下, 再列找最大…
public void solve(int testNumber, InputReader in, OutputWriter out) { int n = in.readInt(); int m = in.readInt(); int[] count = new int[n]; for (int i = 0; i < m; i++) { int[] nums = IOUtils.readIntArray(in,n); int maxIndex = selection(nums); count[maxIndex]++; } out.print(selection(count)+1); } private int selection(int[] nums){ int maxIndex = 0; for (int i = 0; i < nums.length; i++) { if (nums[i] > nums[maxIndex]){ maxIndex = i; } } return maxIndex; }
Leave A Comment