标签:lan img iostream from max 程序 mis script pen
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 3051 Accepted Submission(s): 919
#include<iostream> #include<string.h> #include<algorithm> #include<stdio.h> #include<math.h> #include<queue> #include<stack> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long long ll; typedef pair<int,int> PII; #define mod 1000000007 #define pb push_back #define mp make_pair #define all(x) (x).begin(),(x).end() #define fi first #define se second //head #define MAX 1005 int t; ll n,m; ll a[MAX],b[MAX]; ll nxt[MAX],used[MAX]; bool Find(int x) { for(int i=1;i<=m;i++) { if(!used[i]&&a[x]%b[i]==0) { used[i]=1; if(nxt[i]==0||Find(nxt[i])) { nxt[i]=x; return true; } } } return false; } ll match() { ll sum=0; for(int i=1;i<=n;i++) { memset(used,0,sizeof(used)); if(Find(i)) sum++; } return sum; } int main() { cin>>t; int k=0; while(t--) { memset(nxt,0,sizeof(nxt)); int d,dd; cin>>d>>dd; if(d>dd) swap(d,dd); cout<<"Case #"<<++k<<": "; if(d>1000) cout<<"No"<<endl; else { n=m=d; for(int i=1;i<=d;i++) a[i]=++dd; for(int i=1;i<=d;i++) b[i]=i; if(match()==n) cout<<"Yes"<<endl; else cout<<"No"<<endl; } } return 0; }
#include<iostream> #include<string.h> #include<algorithm> #include<stdio.h> #include<math.h> #include<queue> #include<stack> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long long ll; typedef pair<int,int> PII; #define mod 1000000007 #define pb push_back #define mp make_pair #define all(x) (x).begin(),(x).end() #define fi first #define se second //head #define MAX 1005 int t; int n; vector<int >G[MAX]; int nxt[MAX],used[MAX]; bool Find(int x) { for(int i=0;i<G[x].size();i++) { int v=G[x][i]; if(!used[v]) { used[v]=1; if(nxt[v]==0||Find(nxt[v])) { nxt[v]=x; return true; } } } return false; } int match() { int sum=0; for(int i=1;i<=n;i++) { memset(used,0,sizeof(used)); if(Find(i)) sum++; } return sum; } int main() { scanf("%d",&t); int k=0; while(t--) { for(int i=1;i<=n;i++) G[i].clear(); memset(nxt,0,sizeof(nxt)); int d,dd; scanf("%d %d",&d,&dd); if(d>dd) swap(d,dd); printf("Case #%d: ",++k); if(d>300) printf("No\n"); else { n=d; for(int i=1;i<=d;i++) { int tmp=dd+i; for(int j=1;j<=n;j++) { if(tmp%j==0) G[j].push_back(i); } } if(match()==n) printf("Yes\n"); else printf("No\n"); } } return 0; }
hdu5943 Kingdom of Obsession 二分图+打表找规律
标签:lan img iostream from max 程序 mis script pen
原文地址:https://www.cnblogs.com/zhgyki/p/9998619.html