全部评论
第三题的通项公式。。
var nn = parseInt(readline());
for(let i=0;i<nn;i++){
var n = parseInt(readline());
if(f(n))
print('Yes');
else
print('No');
}
function f(n) {
var tag = n;
var he = 0;
var p = 10;
do{
var s = parseInt(tag/p);
var y = tag%p;
he += y;
tag = s;
}while(s);
//console.log(he);
if(n%he==0)
return true;
else
return false;
}
var nn = parseInt(readline());
var q = readline().split(' ');
var n=1;
var x;
var y;
for(let i=0;i<nn;i++){
x = q.indexOf('1',i);
y = q.indexOf('1',x+1);
if(y==-1)
break;
n *= y-x;
i=x;
}
print(n);
var s = readline();
var a = readline();
var n = 0;
var t = 0;
var slen = s.length;
var alen = a.length;
var x = 0;
for(let i=0;i<slen+1;i++){
let ss = s.slice(i,i+alen);
if(ss==a){
t++;
x = alen-1;
}else{
if(x>0) {
x--;
t++;
}else{
n += t*t;
t = 0;
}
}
}
print(n);
全通过,自己瞎写的 没算法
第二题AC代码,阿Q赢的最少轮数问题:将阿Q最少轮数转换为牛牛赢的最多轮数即可。
import math
values = list(map(int,input().split()))
X = values[0]
Y = values[1]
N = math.sqrt(2*(X+Y)+1/4)-1/2
n = int(math.sqrt(2*Y+1/4)-1/2)
ret = -1
if int(N) == N:
ret = int(N-n)
print(ret)
第一题哈希,第二题贪心,第三题没推出来,目测分情况推公式
90,100,50……
第一题20 第二题10 可能我只会if else for 吧
1.正解是字符串哈希,没板子没写出来,太菜了(听说可以调板子?),拿两个set骗了70。 2.简单贪心,用二分可以求出要多少轮,当然用sqrt也可以直接定,然后从大往小拿,注意不存在的情况。 100. 3.正解容斥,推不出来,n^3可以拿30, 其实还能爆枚x,y,二分check z 可以降到n^2logn没去写可能能再撑死过1-2个点吧?
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{ long long x, y; cin >> x >> y; long long sum = x + y; long long n = sqrt(2 * sum); cout << n; if (n * (n + 1) / 2 != sum) cout << -1 << endl; else { if (x <= n) cout << 1 << endl; else { int count = 0; int t = n; while (x > 0 && t > 0) { if (t <= x) { count += 1; x = x - t; } else { count += 1; break; } t--; } cout << count << endl; } } return 0;
}
做的难道不是同一道题吗?
TX的笔试凉了,三道题都写了,加起来a了0.5。。。
求重要城市的代码,未经过测试,dfs暴力求解 public class Main9 { public static void main(String[] args){ /** Scanner scanner=new Scanner(System.in); String a=scanner.nextLine(); String[] strings=a.split(" "); int k1=Integer.valueOf(strings[0]); int k2=Integer.valueOf(strings[1]); int[][] kk=new int[k1+1][k1+1]; for(int i=0;i<k2;i++){ String a2=scanner.nextLine(); String[] strings1=a2.split(" "); int n1=Integer.valueOf(strings1[0]); int n2=Integer.valueOf(strings1[1]); kk[n1][n2]=1; } **/ int[][] kk=new int[5][5]; kk[1][3]=1; kk[2][1]=1; kk[3][2]=1; kk[4][3]=1; int[][] keda=new int[5][5]; for(int i=1;i<5;i++){ dfs(keda,kk,i,i,0); } for(int i=1;i<keda.length;i++){ for(int j=1;j<keda.length;j++){
System.out.print(keda[i][j]); }
System.out.println(); } int count =0; for(int i=1;i<kk.length;i++){ int chudu=0; for(int d=1;d<kk.length;d++){ if(keda[i][d]==1){
chudu++; }
} int rudu=0; for(int j=1;j<kk.length;j++){ if(keda[j][i]==1){
rudu++; }
} if(rudu>chudu){
count++; }
}
System.out.println(count); } public static void dfs(int[][] keda,int[][] kk,int now,int x,int count){ if(now==x){
count++; } if(count==2){ return; } for(int i=1;i<keda.length;i++){ if(kk[x][i]==1&&now!=i&&keda[now][i]!=1){
keda[now][i]=1; dfs(keda,kk,now,i,count); }
}
}
}
https://blog.csdn.net/u013594470/article/details/82726151
https://www.nowcoder.com/discuss/110827 我写的也不咋地, 共勉
90 AC 60 第三题加了个上界,从30变到60
90 90 30的是不是凉了?
我Android,1、2题AC,第三题等调试通的时候时间结束了QAQ
三角形那个有没有大佬给出AC代码呀,我用的三维数组,内存超出限制,很难受
0.9 AC 0.5 第三题死活内存超限,用long也超限。。。
第3题有大佬AC么?是不是可以用容斥来做啊? a,b,c=list(map(int,input().strip().split(' ')))
res=0
mod=10**9+7
for i in range(1,a+1):
mi,ma=max(1,i-c+1), min(i,b)
res+=(mi+ma)*(ma-mi+1)//2
res%=mod
for i in range(1,b+1):
mi,ma=max(1,i-c+1), min(i,a)
res+=(mi+ma)*(ma-mi+1)//2
res%=mod
for i in range(1,c+1):
mi,ma=max(1,i-a+1), min(i,b)
res+=(mi+ma)*(ma-mi+1)//2
res%=mod
for i in range(1,1+min(a,b)):
res-=min(2*i-1,c)
res%=mod
for i in range(1,1+min(a,c)):
res-=min(2*i-1,b)
res%=mod
for i in range(1,1+min(b,c)):
res-=min(2*i-1,a)
res%=mod
res+=min([a,b,c])
res%=mod
print(res)
第一题ac代码 k = int(input().strip())A = input().strip()B = input().strip() la = len(A)lb = len(B)def getnext(ps): nextarr = [-1 for i in range(len(ps))] nextarr[0] = -1 j=0 k=-1 while j<len(ps)-1: if k==-1 or (k>=0 and ps[j]==ps[k]): j+=1 k+=1 if ps[j] == ps[k]: nextarr[j] = nextarr[k] else: nextarr[j] = k else: k = nextarr[k] return nextarr def kmp(ts,ps):# i,j = 0,0 # i : zhuchuan nextarr = getnext(ps) count = 0 while i<len(ts): if (j==-1 or ts[i]==ps[j]):
i+=1
j+=1
else:
j = nextarr[j]
if j == len(ps):
i = i-j+1
j=0
count+=1
return count
zichuan = {}i = 0res = 0while i < la-k+1: cur = A[i:i+k] if cur not in zichuan: zichuan[cur] = 1 count = kmp(B,cur) res+=count i+=1print(res)
相关推荐