日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 综合教程 >内容正文

综合教程

[BNU弱校联萌]厉兵秣马

發(fā)布時(shí)間:2023/12/13 综合教程 38 生活家
生活随笔 收集整理的這篇文章主要介紹了 [BNU弱校联萌]厉兵秣马 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

比賽鏈接:http://acm.bnu.edu.cn/v3/contest_show.php?cid=6868

一如既往地水…兩題……

A.求兩組點(diǎn)不相交的匹配方案。。二分圖匹配問題,KM算法求最小匹配,取權(quán)值相反數(shù)即可。

  1 #include <algorithm>
  2 #include <iostream>
  3 #include <iomanip>
  4 #include <cstring>
  5 #include <climits>
  6 #include <complex>
  7 #include <fstream>
  8 #include <cassert>
  9 #include <cstdio>
 10 #include <bitset>
 11 #include <vector>
 12 #include <deque>
 13 #include <queue>
 14 #include <stack>
 15 #include <ctime>
 16 #include <set>
 17 #include <map>
 18 #include <cmath>
 19 
 20 using namespace std;
 21 
 22 const int INF = 0x3f3f3f3f;
 23 const int maxn = 110;
 24 int n;
 25 int ans[maxn];
 26 int Left[maxn];
 27 bool S[maxn],T[maxn];
 28 double px[maxn<<1];
 29 double py[maxn<<1];
 30 double Lx[maxn],Ly[maxn];
 31 double dis[maxn][maxn];
 32 
 33 
 34 bool match(int i)
 35 {
 36     S[i]=true;
 37     for(int j=1;j<=n;j++)if(abs(Lx[i]+Ly[j]-dis[i][j])<1e-5&&!T[j])
 38     {
 39         T[j]=true;
 40         if(Left[j]==0||match(Left[j]))
 41         {
 42             Left[j]=i;
 43             return true;
 44         }
 45     }
 46     return false;
 47 }
 48 void update(){
 49     double a=INF;
 50     for(int i=1;i<=n;i++)if(S[i])
 51         for(int j=1;j<=n;j++)if(!T[j])
 52             a=min(a,Lx[i]+Ly[j]-dis[i][j]);
 53     for(int i=1;i<=n;i++){
 54         if(S[i])Lx[i]-=a;
 55         if(T[i])Ly[i]+=a;
 56     }
 57 }
 58 void KM()
 59 {
 60     for(int i=1;i<=n;i++){
 61         Left[i]=Lx[i]=Ly[i]=0;
 62         for(int j=1;j<=n;j++)
 63         {
 64             Lx[i]=max(Lx[i],dis[i][j]);
 65         }
 66     }
 67     for(int i=1;i<=n;i++) 
 68     {
 69         while(1) 
 70         {
 71             memset(S,0,sizeof(S));
 72             memset(T,0,sizeof(T));
 73             if(match(i)) break;
 74             else update();
 75         }
 76     }
 77 }
 78 
 79 inline double dist(double x1, double y1, double x2, double y2) {
 80     return sqrt(((x1-x2)*(x1-x2))+((y1-y2)*(y1-y2)));
 81 }
 82 
 83 int main() {
 84     // freopen("in", "r", stdin);
 85     double x, y;
 86     while(~scanf("%d", &n)) {
 87         memset(ans, 0, sizeof(ans));
 88         memset(px, 0, sizeof(px));
 89         memset(py, 0, sizeof(py));
 90         for(int i = 1; i <= 2*n; i++) {
 91             scanf("%lf %lf", &px[i], &py[i]);
 92         }
 93         for(int i = 1; i <= n; i++) {
 94             for(int j = 1; j <= n; j++) {
 95                 dis[i][j] = -dist(px[i], py[i], px[j+n], py[j+n]);
 96             }
 97         }
 98         KM();
 99         for(int i = 1; i <= n; i++) {
100             ans[Left[i]] = i;
101         }
102         for(int i = 1; i <= n; i++) {
103             printf("%d
", ans[i]);
104         }
105     }
106 }

A

B.方案:一層兩列,一列是當(dāng)前計(jì)數(shù)到的字母,另一列是所有的字母順序排列。例:

 1 5
 2 5 5 2
 3 aaaaa
 4 abcde
 5 
 6 bbbbb
 7 abcde
 8 
 9 ccccc
10 abcde
11 
12 ddddd
13 abcde
14 
15 eeeee
16 abcde

代碼:

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstdlib>
 4 #include <cstring>
 5 #include <iomanip>
 6 #include <cmath>
 7 #include <map>
 8 #include <vector>
 9 #include <string>
10 #include <queue>
11 #include <set>
12 #include <algorithm>
13 
14 using namespace std;
15 
16 int n;
17 
18 void output1(int cnt, int n) {
19     if(cnt >= 26) {
20         for(int i = 0; i < n; i++) {
21             printf("%c", cnt - 26 + 'A');
22         }
23     }
24     else {
25         for(int i = 0; i < n; i++) {
26             printf("%c", cnt + 'a');
27         }
28     }
29 }
30 
31 void output2(int n) {
32     if(n > 26) {
33         for(int i = 0; i < 26; i++) {
34             printf("%c", i + 'a');
35         }
36         for(int i = 0; i < n-26; i++) {
37             printf("%c", i + 'A');
38         }
39     }
40     else {
41         for(int i = 0; i < n; i++) {
42             printf("%c", i + 'a');
43         }
44     }
45     printf("
");
46 }
47 
48 int main() {
49     // freopen("in", "r", stdin);
50     freopen("out", "w", stdout);
51     while(~scanf("%d", &n)) {
52         printf("%d %d %d
", n, n, 2);
53         for(int i = 0; i < n; i++) {
54             output1(i, n);
55             printf("
");
56             output2(n);
57             printf("
");
58         }
59     }
60 }

B

總結(jié)

以上是生活随笔為你收集整理的[BNU弱校联萌]厉兵秣马的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。