上午
1 #include <bits/stdc++.h> 2 #define int long long 3 using namespace std; 4 int ans[20],s; 5 signed main() 6 { 7 freopen("x3.in","r",stdin); 8 freopen("x3.out","w",stdout); 9 int n,l,maxn=-1; 10 cin>>n; 11 for(int i=1;i<=n;i++) 12 { 13 int x; 14 cin>>x; 15 l=0; 16 while(x) 17 { 18 l++; 19 if(x&1) 20 ans[l]++; 21 x>>=1; 22 } 23 maxn=max(maxn,l); 24 } 25 for(int i=1;i<=maxn;i++) 26 s+=(1<<(i-1))*ans[i]*(n-ans[i]); 27 cout<<s; 28 return 0; 29 }
1 //40pts 2 #include <bits/stdc++.h> 3 using namespace std; 4 int n,m,a[500005],zx[500005]; 5 vector < int > v[500005]; 6 int main() 7 { 8 freopen("place.in","r",stdin); 9 freopen("place.out","w",stdout); 10 zx[1]=1; 11 cin>>n>>m>>a[1]; 12 for(int i=2;i<=n;i++) 13 v[1].push_back(i); 14 for(int i=2;i<=n;i++) 15 { 16 int x; 17 cin>>a[i]>>x; 18 zx[i]=x; 19 int p=x; 20 while(zx[p]!=p) 21 { 22 v[p].push_back(i); 23 p=zx[p]; 24 } 25 } 26 /*for(int i=1;i<=n;i++) 27 { 28 cout<<zx[i]<<endl; 29 for(int j=0;j<v[i].size();j++) 30 cout<< 31 }*/ 32 while(m--) 33 { 34 char c; 35 cin>>c; 36 if(c=='p') 37 { 38 int x,y; 39 cin>>x>>y; 40 for(int i=0;i<v[x].size();i++) 41 a[v[x][i]]+=y; 42 } 43 else 44 { 45 int x; 46 cin>>x; 47 cout<<a[x]<<endl; 48 } 49 } 50 return 0; 51 }
1 #include <bits/stdc++.h> 2 #define int long long 3 #define N 1000000000 4 using namespace std; 5 int n,ss[1000005],t,b,k=1,p,l,r,mid; 6 bool bz[100005]; 7 void dfs(int x,int s,int h) 8 { 9 if(x==t || s*ss[x]>mid) 10 { 11 if(h&1) 12 b+=mid/s; 13 else b-=mid/s; 14 return; 15 } 16 if(s*ss[x]<=mid) 17 dfs(x+1,s*ss[x],h+1); 18 dfs(x+1,s,h); 19 } 20 signed main() 21 { 22 freopen("broj.in","r",stdin); 23 freopen("broj.out","w",stdout); 24 cin>>n>>p; 25 if(n==1) 26 { 27 cout<<p; 28 return 0; 29 } 30 else if(p*p>N) 31 { 32 cout<<0; 33 return 0; 34 } 35 for(int i=2;i<=p;i++) 36 { 37 if(!bz[i]) 38 ss[++t]=i; 39 for(int j=1;j<=t;j++) 40 { 41 if(i*ss[j]>p) 42 break; 43 bz[i*ss[j]]=1; 44 if(i%ss[j]==0) 45 break; 46 } 47 } 48 l=p,r=N/p+1; 49 while(l<=r) 50 { 51 mid=l+r>>1; 52 b=mid,dfs(1,1,0); 53 b=mid-b; 54 if (b<n) l=mid+1; 55 else r=mid-1; 56 } 57 if (l*p>N) 58 cout<<0; 59 else 60 cout<<l*p; 61 return 0; 62 }
下午
1 #include <bits/stdc++.h> 2 using namespace std; 3 char a[105][105],s; 4 int main() 5 { 6 freopen("puzzle.in","r",stdin); 7 freopen("puzzle.out","w",stdout); 8 int n; 9 cin>>n; 10 for(int i=1;i<=n;i++) 11 { 12 for(int j=1;j<=n;j++) 13 { 14 cin>>a[i][j]; 15 if(a[i][j]=='#') 16 s++; 17 } 18 } 19 if(s%5!=0) 20 { 21 puts("NO"); 22 return 0; 23 } 24 for(int i=1;i<=n;i++) 25 { 26 for(int j=1;j<=n;j++) 27 { 28 if(a[i][j]=='#') 29 { 30 if(a[i+1][j]=='#' && a[i+1][j-1]=='#' && a[i+1][j+1]=='#' && a[i+2][j]=='#') 31 { 32 a[i+1][j]='.'; 33 a[i+1][j-1]='.'; 34 a[i+1][j+1]='.'; 35 a[i+2][j]='.'; 36 } 37 else 38 { 39 puts("NO"); 40 return 0; 41 } 42 } 43 } 44 } 45 puts("YES"); 46 return 0; 47 }
1 #include<bits/stdc++.h> 2 using namespace std; 3 int n,a[5005],v[5005],ans,m; 4 int main() 5 { 6 freopen("box.in","r",stdin); 7 freopen("box.out","w",stdout); 8 cin>>n; 9 for(int i=1;i<=n;i++) 10 cin>>a[i]; 11 sort(a+1,a+n+1); 12 for(int i=1;i<=n;i++) 13 if(!v[i]) 14 { 15 ans++; 16 m=1; 17 for(int j=i+1;j<=n;j++) 18 if(!v[j]&&a[j]>=m) 19 { 20 v[j]=1; 21 m++; 22 } 23 } 24 cout<<ans<<endl; 25 return 0; 26 }
1 #include <bits/stdc++.h> 2 using namespace std; 3 struct node{ 4 int x,y,z; 5 }f[100005]; 6 int n,m,a[20005],vis[20005]; 7 bool cmp(node a,node vis) 8 { 9 return a.z>vis.z; 10 } 11 int find(int x) 12 { 13 if(a[x]==x) 14 return x; 15 a[x]=find(a[x]); 16 return a[x]; 17 } 18 void add(int x,int y) 19 { 20 x=find(a[x]); 21 y=find(a[y]); 22 a[x]=y; 23 } 24 bool check(int x,int y) 25 { 26 x=find(x); 27 y=find(y); 28 if(x==y) return 1; 29 return 0; 30 } 31 int main() 32 { 33 freopen("love.in","r",stdin); 34 freopen("love.out","w",stdout); 35 cin>>n>>m; 36 for(int i=1;i<=n;i++) 37 a[i]=i; 38 for(int i=1;i<=m;i++) 39 cin>>f[i].x>>f[i].y>>f[i].z; 40 sort(f+1,f+m+1,cmp); 41 for(int i=1;i<=m+1;i++) 42 { 43 if(check(f[i].x,f[i].y)) 44 { 45 cout<<f[i].z; 46 return 0; 47 } 48 else 49 { 50 if(!vis[f[i].x]) 51 vis[f[i].x]=f[i].y; 52 else 53 add(vis[f[i].x],f[i].y); 54 if(!vis[f[i].y]) 55 vis[f[i].y]=f[i].x; 56 else 57 add(vis[f[i].y],f[i].x); 58 } 59 } 60 return 0; 61 }
1 #include <bits/stdc++.h> 2 #define int long long 3 using namespace std; 4 const int mod = 998244353; 5 vector < int > g[300005],v; 6 int a[300005]; 7 bool vis[300005]; 8 int n,m,sum,ans=1; 9 int qsm(int p,int q) 10 { 11 int re=1; 12 while(q!=0) 13 { 14 if(q&1) 15 re=re*p%mod; 16 p=p*p%mod; 17 q>>=1; 18 } 19 return re; 20 } 21 void dfs(int x,int dep) 22 { 23 vis[x]=1; 24 a[x]=dep; 25 for(int i=0;i<g[x].size();i++) 26 { 27 int t=g[x][i]; 28 if(vis[t] && dep-a[t]>1) 29 v.push_back(dep+1-a[t]); 30 else if(!vis[t]) 31 dfs(t,dep+1); 32 } 33 vis[x]=1; 34 } 35 signed main() 36 { 37 freopen("desert.in","r",stdin); 38 freopen("desert.out","w",stdout); 39 cin>>n>>m; 40 for(int i=1;i<=m;i++) 41 { 42 int x,y; 43 cin>>x>>y; 44 g[x].push_back(y); 45 g[y].push_back(x); 46 } 47 for(int i=1;i<=n;i++) 48 if(!vis[i]) 49 dfs(i,1); 50 for(int i=0;i<v.size();i++) 51 { 52 ans=ans*(qsm(2,v[i])-1)%mod; 53 sum+=v[i]; 54 } 55 ans=ans*qsm(2,m-sum)%mod; 56 cout<<ans; 57 return 0; 58 }
标签:std,8.5,记录,int,20,做题,freopen,using,return From: https://www.cnblogs.com/wyh0721/p/17608238.html