成为权限狗了……蛋疼地刷点Usaco的水题,话说明天又要滚回新校被文化科虐爆了,不爽啊啊啊
/************************************************************** Problem: 1600 User: zky Language: C++ Result: Accepted Time:0 ms Memory:1280 kb ****************************************************************/ #include<iostream> using namespace std; int n,f[2505]; int main(){ cin>>n; f[4]=1; for (int i=5;i<=n;i++) if (!(i&1)) f[i]=f[i-1]+i/2-1; else f[i]=f[i-1]+(i-2)*(i/2-1); cout<<f[n]<<endl; return 0; }
/************************************************************** Problem: 1601 User: zky Language: C++ Result: Accepted Time:92 ms Memory:2780 kb ****************************************************************/ //ID:zky #include<cstdio> #include<vector> #include<iostream> #include<algorithm> using namespace std; const int maxn=310; int n; struct edge{ int u,v,w,ind; bool operator < (const edge &e)const{ return w<e.w; } };int tot; edge edges[maxn*maxn+maxn]; int fa[maxn],minn=100000; int find(int x){ if(x!=fa[x])return fa[x]=find(fa[x]);return x; } int main(){ int n;scanf("%d",&n);fa[n+1]=n+1; for(int i=1;i<=n;i++){ fa[i]=i; int w;scanf("%d",&w);minn=min(minn,w); edges[tot]=(edge){i,n+1,w,tot};tot++; } for(int i=1;i<=n;i++) for(int j=1;j<=n;j++){ int x;scanf("%d",&x); if(i>=j)continue; edges[tot]=(edge){i,j,x,tot};tot++; }sort(edges,edges+tot); int ans=0,get=0; for(int i=0;i<tot;i++){ int u=edges[i].u,v=edges[i].v; if(find(u)!=find(v)){ fa[find(u)]=find(v); if(edges[i].ind<=n)get=1; ans+=edges[i].w; } }if(!get)ans+=minn; cout<<ans<<endl; return 0; }
/************************************************************** Problem: 1602 User: zky Language: C++ Result: Accepted Time:152 ms Memory:1288 kb ****************************************************************/ #include<bits/stdc++.h> using namespace std;typedef pair<int,int> pii; vector<pair<int,int> >G[1001]; int n,m; main(){ cin>>n>>m;int s,t; for(int i=0;i<n-1;i++){ int u,v,w;cin>>u>>v>>w; G[u].push_back(pii(v,w)); G[v].push_back(pii(u,w)); }while(m--){int d[1233];int vis[1233];memset(d,0x7f,sizeof(d)); memset(vis,0,sizeof(vis));cin>>s>>t; queue<int>q;q.push(s);d[s]=0;while(!q.empty()){ int u=q.front();q.pop();vis[u]=0; for(int i=0;i<G[u].size();i++){ int v=G[u][i].first,w=G[u][i].second; if(d[v]>d[u]+w){ d[v]=d[u]+w;if(!vis[v]){ vis[v]=1;q.push(v); } } } }cout<<d[t]<<endl; } }
/************************************************************** Problem: 1603 User: zky Language: C++ Result: Accepted Time:20 ms Memory:1280 kb ****************************************************************/ #include<bits/stdc++.h> using namespace std; int n; int next[1001]; int w[1001]; int main(){ cin>>n; for(int i=0;i<n-1;i++){ int u,v,ww;cin>>u>>v>>ww; next[u]=v;w[u]=ww; }int ans=0; for(int i=1;i;i=next[i]) ans^=w[i]; cout<<ans<<endl; return 0; }
/************************************************************** Problem: 1604 User: zky Language: C++ Result: Accepted Time:988 ms Memory:4680 kb ****************************************************************/ #include<bits/stdc++.h> using namespace std; const int maxn=1e5+10; int n,m,a[maxn],c[maxn]; struct point { int x,y,i; bool operator<(const point &p)const { if(y==p.y)return x<p.x; return y<p.y; } } p[maxn]; set<point>mset; set<point>::iterator ii,it; bool cmp(point p1,point p2) { return p1.x<p2.x; } inline int find(int x) { int r=x,p; while(r!=a[r])r=a[r]; while(r!=x) { p=a[x]; a[x]=r; x=p; } return r; } void unit(int x,int y) { x=find(x); y=find(y); if(x!=y)a[y]=x; } void slove() { int i,j=1,k,x,y,sum,ans; mset.clear(); mset.insert(p[1]); for(i=2; i<=n; i++) { while(p[i].x-p[j].x>m&&j<i) { mset.erase(p[j]); j++; } mset.insert(p[i]); ii=it=mset.find(p[i]); ii--; it++; if(ii!=mset.end()&&abs(ii->y-p[i].y)<=m)unit(i,ii->i); if(it!=mset.end()&&abs(it->y-p[i].y)<=m)unit(i,it->i); } sum=ans=0; for(i=1; i<=n; i++)c[find(i)]++; for(i=1; i<=n; i++) { ans=max(ans,c[i]); if(a[i]==i)sum++; } printf("%d %d\n",sum,ans); } int main() { int i,j,k,x,y; while(scanf("%d%d",&n,&m)!=EOF) { for(i=1; i<=n; i++) { scanf("%d%d",&x,&y); p[i].x=x+y; p[i].y=x-y; a[i]=i; c[i]=0; } sort(p+1,p+n+1,cmp); for(i=1; i<=n; i++)p[i].i=i; slove(); } return 0; }
/************************************************************** Problem: 1606 User: zky Language: C++ Result: Accepted Time:280 ms Memory:1340 kb ****************************************************************/ #include <bits/stdc++.h> using namespace std; int c,h,v[5001]; bool f[50001]; int main() { cin>>c>>h; for(int i=1;i<=h;i++) cin>>v[i]; f[0] = true; for(int i=1;i<=h;i++) for(int j=c;j>=v[i];j--){ if (!f[j]&&f[j-v[i]]) f[j]=true; } int ans=c; while(ans>1&&!f[ans]) ans--; cout<<ans<<endl; return 0; }