我这种蒟蒻也要开始做网络流了啊qwq
二分图匹配**题,匈牙利都能过
1 #include<bits/stdc++.h> 2 using namespace std; 3 bool vis[101]; 4 int match[101] , head[101] , cnt; 5 struct Edge{ 6 int end , upEd; 7 }Ed[10001]; 8 inline void add(int a , int b){ 9 Ed[++cnt].end = b; Ed[cnt].upEd = head[a]; head[a] = cnt; 10 } 11 bool dfs(int a){ 12 for(int i = head[a] ; i ; i = Ed[i].upEd) 13 if(!vis[Ed[i].end]){ 14 vis[Ed[i].end] = 1; 15 if(!match[Ed[i].end] || dfs(match[Ed[i].end])){ 16 match[Ed[i].end] = a; 17 return 1; 18 } 19 } 20 return 0; 21 } 22 int main(){ 23 int M , N , ans = 0 , a , b; 24 scanf("%d%d%d%d" , &M , &N , &a , &b); 25 while(a != -1){ 26 add(a , b - M); 27 scanf("%d%d" , &a , &b); 28 } 29 for(int i = 1 ; i <= M ; i++){ 30 memset(vis , 0 , sizeof(vis)); 31 dfs(i); 32 } 33 for(int i = 1 ; i + M <= N ; i++) ans += (bool)match[i]; 34 if(ans == 0) cout << "No Solution!"; 35 else{ 36 cout << ans << endl; 37 for(int i = 1 ; i + M <= N ; i++) 38 if(match[i]) cout << match[i] << ‘ ‘ << i + M << endl; 39 } 40 return 0; 41 }
环形均分纸牌大法吼啊
1 #include<bits/stdc++.h> 2 using namespace std; 3 inline int read(){ 4 int a = 0; 5 char c = getchar(); 6 while(!isdigit(c)) c = getchar(); 7 while(isdigit(c)) a = (a << 3) + (a << 1) + (c ^ ‘0‘) , c = getchar(); 8 return a; 9 } 10 inline int abs(int a){ 11 return a > 0 ? a : -a; 12 } 13 long long S[1000001]; 14 int main(){ 15 int n = read(); 16 long long sum = 0; 17 for(int i = 1 ; i <= n ; i++) 18 sum += S[i] = read(); 19 sum /= n; 20 for(int i = 1 ; i <= n ; i++) 21 S[i] += S[i - 1] - sum; 22 sort(S + 1 , S + n + 1); 23 sum = 0; 24 for(int i = 1 ; i <= n ; i++) 25 sum += abs(S[i] - S[n + 1 >> 1]); 26 printf("%lld" , sum); 27 return 0; 28 }
原文地址:https://www.cnblogs.com/Itst/p/9786016.html
时间: 2024-11-09 13:38:46