Review of Codeforces 6B and 6C
来源:互联网 发布:软件项目计划书 编辑:程序博客网 时间:2024/04/30 21:23
6B. President's Office
This question is about using 'set' in pyhon. set has a property that it only add elements that not included in the current set. which is an ideal tool in this question.
First add '.' and 'C(the president's color)' in the set and then search the matrix and when it find 'C', it search around the element and add the alphabeta that not included in the set.
The source code is:
n, m, c = raw_input().split()n, m = map(int, [n, m])a = [raw_input() for i in xrange(n)]s = set(['.', c])for i in xrange(n):for j in xrange(m):if a[i][j] == c:for x, y in [(i - 1, j), (i + 1, j), (i, j - 1), (i, j + 1)]:if x >= 0 and x < n and y >= 0 and y < m: s.add(a[x][y])print len(s) - 2
I also have an other idea, but is trival and has wrong answer. I dont't know why.
6C. Alice, Bob and Chocolate
This question is about greedy algorithm. The only thing you need to remind is there are corner cases in this task when n== 1 and n == 2. every time compare the time consumed by alice and bob, and add one chocolate to the fewer one. The source code as follows:
n = input()a = list(map(int, raw_input().split()))i = 0j = n-1m = a[i]k = a[j]if n == 1:print 1, 0elif n == 2:print 1, 1else:while j-i != 1:if (m <= k):i += 1m += a[i]elif (m > k):j -= 1k += a[j]print i+1, n - j
also, you need to be care the output is i+1 and n-j
0 0
- Review of Codeforces 6B and 6C
- Review of Codeforces 5A and 5B(Python)
- Review of codeforces 483B Friends and Presents
- Review of codeforces 486B
- Review of codeforces 493B Vasya and Wrestling based on Python
- Review of codeforces 492C Vanya and Computer Game based on Python
- Review of Codeforces 5C. Longest Regular Bracket Sequence
- Codeforces Round #302 (Div. 2) A.Set of Strings&B.Sea and Islands&C.Writing Code
- codeforces 400B. Inna and New Matrix of Candies
- codeforces 400B - Inna and New Matrix of Candies
- codeforces 400B Inna and New Matrix of Candies
- Inna and New Matrix of Candies(CodeForces - 400B)
- Codeforces 400B Inna and New Matrix of Candies 【模拟】
- Codeforces 679B Bear and Tower of Cubes 【贪心】
- CodeForces 679B - Bear and Tower of Cubes
- CodeForces 679B(Bear and Tower of Cubes)
- codeforces 679B Bear and Tower of Cubes(贪心+dfs)
- codeforces 679B Bear and Tower of Cubes(贪心+dfs)
- __int64 与long long 的区别
- 第十二周项目一——阅读程序1(有静态局部变量的程序)
- 老师,请不要这样讲中国
- android 判断登录是否邮箱或手机号
- Problem A Forever 0.5(推理构造)
- Review of Codeforces 6B and 6C
- 第十二周上机项目三
- HDU 5095 Linearization of the kernel functions in SVM(模拟)
- POJ 2406--Power Strings(kmp算法)
- 实验四
- hdu 5104 Primes Problem(数学)
- Objective-C基础笔记(4)Category
- JAVA的反射机制与动态代理
- LeetCode - Text Justification 题解