zoukankan      html  css  js  c++  java
  • CSUOJ 1531 Jewelry Exhibition

    Problem G

    Jewelry Exhibition

    To guard the art jewelry exhibition at night, the security agency has decided to use a new laser beam system, consisting of sender-receiver pairs. Each pair generates a strip of light of one unit width and guards all objects located inside the strip. Your task is to help the agency and to compute for each exhibition room the minimum number of sender-receiver pairs which are sufficient to protect all exhibits inside the room.

    Any room has a rectangle shape, so we describe it as an [0,N] × [0,M] rectangle in the plane. The objects we need to guard are represented as points inside that rectangle. Each sender is mounted on a wall and the corresponding receiver on the opposite wall in such a way that the generated strip is a rectangle of unit width and length either N or M. Since the new laser beam system is still not perfect, each sender-receiver pair can only be mounted to generate strips the corners of which have integer coordinates. An additional drawback is that the sender-receiver pairs can protect only items inside the strips, but not those lying on their borders. Thus, the security agency arranged the exhibits in such a way that both coordinates of any point representing an exhibit are non-integers. The figure below (left) illustrates eight items arranged in [0,4]×[0,4] (the second sample input). In the room, up to eight sender-receiver pairs can be mounted. The figure to the right shows an area protected by three sender-receiver pairs.

     

    Input

    The input starts with the number of exhibition rooms R ≤ 10. Then the descriptions of the R rooms follow. A single description starts with a single line, containing three integers: 0 < N ≤ 100, 0 < M ≤ 100, specifying the size of the current room and 0 < K ≤ 104, for the number of exhibits. Next K lines follow, each of which consists of two real numbers x,y describing the exhibit coordinates. You can assume that 0 < x < N, 0 < y < M and that x and y are non-integer.

    Output

    For every room output one line containing one integer, that is the minimum number of sender-receiver pairs sufficient to protect all exhibits inside the room.

    Sample Input                                                                  Sample Output

    2                                                                                    1

    1 5 3                                                                              3

    0.2 1.5

    0.3 4.8

    0.4 3.5

    4 4 8

    0.7 0.5

    1.7 0.5

    2.8 1.5

    3.7 0.5

    2.2 3.6

    2.7 2.7

    1.2 2.2

    1.2 2.7

     解题:最大匹配

    匈牙利算法

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 using namespace std;
     5 const int maxn = 110;
     6 bool e[maxn][maxn],used[maxn];
     7 int linker[maxn],U,V;
     8 bool dfs(int u) {
     9     for(int i = 0; i < V; ++i) {
    10         if(e[u][i] && !used[i]) {
    11             used[i] = true;
    12             if(linker[i] == -1 || dfs(linker[i])) {
    13                 linker[i] = u;
    14                 return true;
    15             }
    16         }
    17     }
    18     return false;
    19 }
    20 int main() {
    21     int ks,n;
    22     double x,y;
    23     scanf("%d",&ks);
    24     while(ks--) {
    25         scanf("%d%d%d",&U,&V,&n);
    26         memset(linker,-1,sizeof(linker));
    27         memset(e,false,sizeof(e));
    28         for(int i = 0; i < n; ++i) {
    29             scanf("%lf %lf",&x,&y);
    30             e[(int)x][(int)y] = true;
    31         }
    32         int ans = 0;
    33         for(int i = 0; i < U; ++i) {
    34             memset(used,false,sizeof(used));
    35             ans += dfs(i);
    36         }
    37         printf("%d
    ",ans);
    38     }
    39     return 0;
    40 }
    View Code

    最大流

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <queue>
     4 #include <cstring>
     5 #define INF 0x3f3f3f3f
     6 using namespace std;
     7 const int maxn = 300;
     8 struct arc{
     9     int to,flow,next;
    10     arc(int x = 0,int y = 0,int z = -1){
    11         to = x;
    12         flow = y;
    13         next = z;
    14     }
    15 }e[maxn*maxn*10];
    16 int head[maxn],d[maxn],cur[maxn],tot,S,T;
    17 void add(int u,int v,int flow){
    18     e[tot] = arc(v,flow,head[u]);
    19     head[u] = tot++;
    20     e[tot] = arc(u,0,head[v]);
    21     head[v] = tot++;
    22 }
    23 bool bfs(){
    24     queue<int>q;
    25     memset(d,-1,sizeof(d));
    26     d[S] = 0;
    27     q.push(S);
    28     while(!q.empty()){
    29         int u = q.front();
    30         q.pop();
    31         for(int i = head[u]; ~i; i = e[i].next){
    32             if(e[i].flow && d[e[i].to] == -1){
    33                 d[e[i].to] = d[u] + 1;
    34                 q.push(e[i].to);
    35             }
    36         }
    37     }
    38     return d[T] > -1;
    39 }
    40 int dfs(int u,int low){
    41     if(u == T) return low;
    42     int tmp = 0,a;
    43     for(int &i = cur[u]; ~i; i = e[i].next){
    44         if(e[i].flow && d[e[i].to] == d[u] + 1&&(a=dfs(e[i].to,min(low,e[i].flow)))){
    45             e[i].flow -= a;
    46             e[i^1].flow += a;
    47             low -= a;
    48             tmp += a;
    49             if(!low) break;
    50         }
    51     }
    52     if(!tmp) d[u] = -1;
    53     return tmp;
    54 }
    55 int solve(){
    56     int ans = 0;
    57     while(bfs()){
    58         memcpy(cur,head,sizeof(head));
    59         ans += dfs(S,INF);
    60     }
    61     return ans;
    62 }
    63 int main(){
    64     int ks,n,m,k;
    65     double x,y;
    66     scanf("%d",&ks);
    67     while(ks--){
    68         scanf("%d %d %d",&n,&m,&k);
    69         memset(head,-1,sizeof(head));
    70         for(int i = tot = 0; i < k; ++i){
    71             scanf("%lf %lf",&x,&y);
    72             add((int)x,n+(int)y,1);
    73         }
    74         S = n + m;
    75         T = S + 1;
    76         for(int i = 0; i < n; ++i)
    77             add(S,i,1);
    78         for(int i = 0; i < m; ++i)
    79             add(i+n,T,1);
    80         printf("%d
    ",solve());
    81     }
    82     return 0;
    83 }
    View Code
  • 相关阅读:
    离线语音
    云知声语音开发
    自定义View -- 柱状图 我也来自定义个柱状图来玩玩
    android studio中如何替换gradle以防下载卡住
    如何查询当前手机的cpu架构,so库导入工程又出异常了?
    android 学习mvc 和 mvp 和 mvvm参考项目
    【整理】Android中EditText中的InputType类型含义与如何定义( 转 )
    Android点击EditText文本框之外任何地方隐藏键盘的解决办法
    Android开发 adb命令提示:Permission denied (转)
    Node.js-串行化流程控制
  • 原文地址:https://www.cnblogs.com/crackpotisback/p/4344320.html
Copyright © 2011-2022 走看看