Menu Sidebar
Menu

Archive: August 13, 2015

Codeforces Round #316 (Div. 2) C. Replacement

原题: http://codeforces.com/contest/570/problem/C 题目大意: 给一个string s, s有小写字母和’.’组成. 做m个query替换操作, 对于每个操作都要进行固定的处理, 这个处理是把s中的连续两个’.’. 替换成1个, 一次替换消除一对’.’ 问对每个query, 需要几次替换. 分析: 开始的时候以为能爆过….结果暴到test case7 过不去了…后来只能分情况讨论. 一上来先算下原始的s需要几次替换, 假设原始string s 需要n次替换.  这时, 对于m个query, 有两种情况可以改变n的值. 替换的字符是’.’ 但是当前字符不是, 有以下两种情况: 如果当前字符的前边是’.’, n++ 如果当前字符的后边是’.’, n++ 替换的字符是字母, 但是当前字符是’.’, 有以下两种情况: 如果当前字符的前边是’.’, n– 如果当前字符的后边是’.’, n– 最后别忘了把字符替换一下. public void solve(int testNumber, InputReader in, OutputWriter out) { int len = in.readInt(); int m = in.readInt(); […]

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); […]

[LintCode] Maximal Square

public int maxSquare(int[][] matrix) { // write your code here if(matrix == null || matrix.length == 0) return 0; int[] height = new int[matrix[0].length]; int res = 0; for(int i = 0 ; i < matrix.length; i++) { for(int j = 0; j < matrix[0].length; j++) { if(matrix[i][j] == 1) height[j]++; else height[j] = 0; […]

[LintCode] Linked List Cycle

public boolean hasCycle(ListNode head) { // write your code here if(head == null) return false; ListNode fast = head; ListNode slow = head; while(fast.next != null && fast.next.next != null) { slow = slow.next; fast = fast.next.next; if(slow == fast) return true; } return false; }

书脊

这青苔碧瓦堆, 俺曾睡风流觉, 将五十年兴亡看饱.

August 2015
M T W T F S S
 12
3456789
10111213141516
17181920212223
24252627282930
31