暴力大法好!!!
- 这里所有的所解答的题目,没有经过验证,仅供提供思路(~)
A 求余
B 双阶乘
sum1 = 1
cnt = 1
while(cnt<=3):
sum1= (sum1 * cnt)%100000
cnt+=2
print(sum1)
C 格点
nums = 0
for i in range(1,2022):
for j in range(1,2022):
if i*j <= 2021:
nums+=1
print(nums)
D 整数分解
- 这一题,单纯的暴力,没有那么获取答案,一开始用python写的代码,速度太慢了,由于它是填空题,后面我用的C跑出的答案(时间也不短)
#include
int main(){
int nums=0;
int i1,i2,i3,i4,i5;
for(i1=1;i1<2021;i1++){
for(i2=1;i2<2021-i1;i2++){
for(i3=1;i3<2021-i1-i2;i3++){
for(i4=1;i4<2021-i1-i2-i3;i4++){
if((2021-i1-i2-i3-i4)>=1){
nums++;
}
}
}
}
}
printf("%d",nums);
return 0;
}
E 城邦
def func(i,j):
strs1 = str(i)
strs2 = str(j)
len1 = len(strs1)
len2 = len(strs2)
sum1 = 0
if len1==len2:
for i in range(1,len1+1):
cnt = -1*i
if strs1[cnt]!=strs2[cnt]:
sum1+=int(strs1[cnt])+int(strs2[cnt])
elif len1>len2:
for i in range(1,len2+1):
cnt = -1*i
if strs1[cnt]!=strs2[cnt]:
sum1+=int(strs1[cnt])+int(strs2[cnt])
for i in range(len2+1,len1+1):
cnt = -1*i
sum1+=int(strs1[cnt])
elif len1<len2:
for i in range(1,len1+1):
cnt = -1*i
if strs1[cnt]!=strs2[cnt]:
sum1+=int(strs1[cnt])+int(strs2[cnt])
for i in range(len1+1,len2+1):
cnt = -1*i
sum1+=int(strs2[cnt])
return sum1
print(func(2021,922))
ans = 0
for i in range(1,2021):
for j in range(i+1,2021):
ans+=func(i,j)
print(ans)
F 小平方
n = int(input())
n_ban = 1.0*n / 2
ans = 0
for i in range(1,n):
cnt = (i**2) % n
if (1.0*cnt)<n_ban:
ans+=1
print("{:.0f}".format(ans))
G 完全平方数
import math
def func(num):
flag = 0
for i in range(int(math.sqrt(num))+1):
if i*i == num:
flag = 1
break
if i*i >num:
break
if flag == 1:
return True
else:
return False
n = int(input())
ans = 0
for x in range(1,n+1):
if func(n*x):
ans = x
break
print("{:.0f}".format(ans))
H 负载均衡
"""
2(计算机数) 6(任务数)
5 5 (计算机运算能力)
ai(时刻) bi(计算机编号) ci(秒) di(算力)
2 6
5 5
1 1 5 3
2 2 2 6
3 1 2 3
4 1 6 1
5 1 3 3
6 1 3 4
#D 187539689
"""
class PC:
def __init__(self,id,xingneng):
self.id = id
self.xingneng = xingneng
self.useing_xingneng = []
self.shengyv_time = []
self.shengyv_xingneng = xingneng
self.shengyv_renwu = 0
com_nums,thing_nums = map(int,input().split())
com_ablity = [int(i) for i in input().split()]
things = []
for _ in range(thing_nums):
temp = [int(i) for i in input().split()]
things.append(temp)
PCS = []
for i in range(com_nums):
pc = PC(i+1,com_ablity[i])
PCS.append(pc)
now_time = 0
thing_flag = 0
while(thing_flag<thing_nums):
for i in range(com_nums):
pc = PCS[i]
if pc.shengyv_renwu != 0:
for j in range(len(pc.shengyv_time)):
pc.shengyv_time[j]-=1
if pc.shengyv_time[j]==0:
pc.shengyv_xingneng += pc.useing_xingneng[j]
pc.useing_xingneng[j]=0
pc.shengyv_renwu-=1
pc.useing_xingneng = [i for i in pc.useing_xingneng if i!=0]
pc.shengyv_time = [i for i in pc.shengyv_time if i!=0]
if now_time == things[thing_flag][0]:
bi,ci,di = things[thing_flag][1],things[thing_flag][2],things[thing_flag][3]
thing_flag+=1
if di<=PCS[bi-1].shengyv_xingneng:
PCS[bi-1].useing_xingneng.append(di)
PCS[bi-1].shengyv_time.append(ci)
PCS[bi-1].shengyv_xingneng-=di
PCS[bi-1].shengyv_renwu+=1
print("{:.0f}".format(PCS[bi-1].shengyv_xingneng))
else:
print("-1")
now_time+=1
I 国际象棋
- 思路:这一题,当时没想到好的算法,我使用的递归来实现的(得不了满分,会超时,如果有好的算法,欢迎留言)
def func(p1,p2):
flag = 0
if (p1[0]+1)==p2[0] and (p1[1]+2)==p2[1]:
flag = 1
elif (p1[0]+1)==p2[0] and (p1[1]-2)==p2[1]:
flag = 1
elif (p1[0]-1)==p2[0] and (p1[1]+2)==p2[1]:
flag = 1
elif (p1[0]-1)==p2[0] and (p1[1]-2)==p2[1]:
flag = 1
elif (p1[0]+2)==p2[0] and (p1[1]+1)==p2[1]:
flag = 1
elif (p1[0]+2)==p2[0] and (p1[1]-1)==p2[1]:
flag = 1
elif (p1[0]-2)==p2[0] and (p1[1]+1)==p2[1]:
flag = 1
elif (p1[0]-2)==p2[0] and (p1[1]-1)==p2[1]:
flag = 1
if flag == 1:
return True
else:
return False
def zb_and_zbs(zb,zbs):
if len(zbs)==0:
return False
else:
flag = 0
for zb2 in zbs:
if func(zb,zb2):
flag = 1
break
if flag == 1:
return True
else:
return False
def dg(zbs,all_zb,K,i):
global ans
if len(zbs)==K:
ans= (ans+1)%1000000007
elif len(zbs)<K:
for j in range(i,len(all_zb)):
one_zb = all_zb[j]
zbs1 = zbs[:]
if (one_zb not in zbs) and (not zb_and_zbs(one_zb,zbs)):
zbs1.append(one_zb)
dg(zbs1,all_zb,K,j+1)
n,m,K = map(int,input().split())
all_zb = []
for i in range(n):
for j in range(m):
all_zb.append([i,j])
zbs = []
global ans
ans = 0
for i in range(len(all_zb)):
zbs = [all_zb[i]]
dg(zbs,all_zb,K,i+1)
print(ans)
J