【BZOJ】【刷题合集】【P1002】【P1192】【P1083】【P1854】【P1433】【#4】

传送门:

http://www.lydsy.com/JudgeOnline/problem.php?id=1002

http://www.lydsy.com/JudgeOnline/problem.php?id=1192

http://www.lydsy.com/JudgeOnline/problem.php?id=1083

http://www.lydsy.com/JudgeOnline/problem.php?id=1854

http://www.lydsy.com/JudgeOnline/problem.php?id=1433

#ID:zky
#OJ:BZOJ
#Index:1002
#Lanuage:Python
f=[0]*111
f[1]=1
f[2]=5
n=int(raw_input())
for i in range(3,n+1):
    f[i]=3*f[i-1]+2
    f[i]-=f[i-2]
print f[n]

#include<cstdio>
#include<cmath>
int main(){
	int n;
	scanf("%d",&n);
	printf("%d\n",int(log2(n)+1));
}

/*
	ID:zky
	OJ:BZOJ
	Index:1083
	Language:C++
*/
#include<vector>
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
struct edge{
	int u,v,w;
	bool operator<(const edge &a)const{
		return w<a.w;
	}
};
vector<edge>edges;
int fa[100001];
int find(int x){
	if(fa[x])return fa[x]=find(fa[x]);
	return x;
}
int main(){
	int n,m;
	cin>>n>>m;
	for(int i=0;i<m;i++){
		int u,v,w;
		cin>>u>>v>>w;
		edges.push_back((edge){u,v,w});
	}
	int ans=0;
	int answ=0;
	sort(edges.begin(),edges.end());
	for(int i=0;i<m;i++){
		if(find(edges[i].u)!=find(edges[i].v)){
			fa[find(edges[i].u)]=find(edges[i].v);
			ans++;
			answ=max(answ,edges[i].w);
		}
	}
	cout<<ans<<" "<<answ<<endl;
	return 0;
}

/*
	ID:zky
	OJ:BZOJ
	Index:1854
	Language:C++
*/
#include<vector>
#include<bitset>
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int n;
bitset<1000002>vis;
int Link[1000002];
vector<vector<int> >w(10002);
bool find(int x){
	for(int i=0;i<w[x].size();i++){
		if(!vis[w[x][i]]){
			vis[w[x][i]]=1;
			if(!Link[w[x][i]]||find(Link[w[x][i]])){
				Link[w[x][i]]=x;
				return true;
			}
		}
	}
	return false;
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		int a,b;
		scanf("%d%d",&a,&b);
		w[a].push_back(i);
		w[b].push_back(i);
	}
	for(int i=1;i<=10001;i++){
		//memset(vis,0,sizeof(vis));
		vis=0;
		if(!find(i)){
			cout<<i-1<<endl;
			return 0;
		}
	}
	return 0;
}

/*
	ID:zky
	OJ:BZOJ
	Index:1433
	Language:C++
*/
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int vis[1010];
int Link[1010];
int w[51][51];
int map[51][51];
int school[51];
int Left[51];
int n;
bool find(int x){
	for(int i=1;i<=n;i++){
		if(w[x][i]&&!vis[i]){
			vis[i]=1;
			if(!Link[i]||find(Link[i])){
				Link[i]=x;
				return true;
			}
		}
	}
	return false;
}
int main(){
	int T;
	cin>>T;
	while(T--){
		memset(Link,0,sizeof(Link));
		memset(w,0,sizeof(w));
		memset(map,0,sizeof(map));
		memset(school,0,sizeof(school));
		memset(Left,0,sizeof(Left));

		cin>>n;
		int l=0;
		for(int i=1;i<=n;i++)cin>>school[i];
		for(int i=1;i<=n;i++)cin>>Left[i];
		for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
		cin>>map[i][j];

		for(int i=1;i<=n;i++){
			if(Left[i]&&school[i])l++;
			if(Left[i]&&school[i])continue;

			if(school[i])
			w[i][i]=1;
			for(int j=1;j<=n;j++){
				if(map[i][j]&&school[j]){
					w[i][j]=1;
				}
			}
		}
		int ans=0;
		for(int i=1;i<=n;i++){
			memset(vis,0,sizeof(vis));
			if(find(i))ans++;
		}
		char s1[]={94,95,94};
		char s2[]={84,95,84};
		if(ans==n-l){
			cout<<"^_^"<<endl;
		}else
			cout<<"T_T"<<endl;
	}
	return 0;
}



你可能感兴趣的:(数论,网络流,bzoj)