Codeforces Round #419 (Div. 2) ABC

python 2.7,用来熟悉Python
由于都是智障题,所以我也不讲述题意和题解,直接贴代码了……

A

import sys
h,m = map(int,raw_input().split(":"))
ans = 0
while True:
    if h%10 == m/10 and h/10 == m%10:
        break
    ans = ans + 1
    h,m = (h+m/59)%24,(m+1)%60
print ans

B

import sys
maxn = 200005
# class bit:
#     def __init__(self):
#         self.a = []
#         for i in xrange(maxn):
#             self.a.append(0)
#     def lowbit(self,x):
#         return x&(-x)
#     def update(self,x,y):
#         i=x
#         while i < maxn:
#             self.a[i] += y
#             i+=self.lowbit(i)
#     def get(self,x):
#         ans=0
#         i=x
#         while i > 0:
#             ans=ans+self.a[i]
#             i-=self.lowbit(i)
#         return ans
b = [0]*maxn
l = [0]*maxn
# Bit = bit()
n,k,m= map(int,raw_input().split())
for i in range(0,n):
    a,b=map(int,raw_input().split())
    l[a]=l[a]+1
    l[b+1]=l[b+1]-1
tmp=0
ans=[0]
for i in range(1,maxn):
    tmp=tmp+l[i]
    ans2=0
    if tmp >= k:
        ans2=1
    ans.append(ans2)
    ans[i]=ans[i]+ans[i-1]
for i in range(0,m):
    a,b=map(int,raw_input().split())
    print ans[b]-ans[a-1]

C

import sys
def read():
    return map(int,raw_input().split())
n,m=read()
g=[list(read()) for i in range(n)]
a=[g[i][0]-g[0][0] for i in range(n)]
b=[g[0][i]-g[0][0] for i in range(m)]
for i in range(n):
    for j in range(1,m):
        if g[i][j] - g[i][0] != b[j]:
            print "-1"
            exit()
for j in range(m):
    for i in range(1,n):
        if g[i][j] - g[0][j] != a[i]:
            print "-1"
            exit()
mn=min(min(i) for i in g)
mb=min(b)
for i in range(m):
    b[i]-=mb
ma=min(a)
for i in range(n):
    a[i]-=ma
if n<m:
    for i in range(n):a[i]+=mn
else:
    for i in range(m):b[i]+=mn
print(sum(a)+sum(b))
for i in range(n):
    for j in range(a[i]):
        print "row",i+1
for i in range(m):
    for j in range(b[i]):
        print "col",i+1
posted @ 2017-06-20 18:16 qscqesze 阅读(...) 评论(...) 编辑 收藏