zoukankan      html  css  js  c++  java
  • 排座椅(贪心)

    浴谷1056

    题意:Noip2008普及组第二题

    分析:因为要求最少的讨论组数,并按照升序输出。首先,我们统计去掉那一行(列)最多可以让多少组的人停止讨论,并把结果按照降序排序,然后我们再将结果按照编号的升序排序即可

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <string>
     5 #include <vector>
     6 #include <algorithm>
     7 #include <set>
     8 #include <map>
     9 #include <bitset>
    10 #include <cmath>
    11 #include <queue>
    12 #include <stack>
    13 using namespace std;
    14 const int maxn=2020;
    15 typedef struct point
    16 {
    17     int num,id;
    18 }point;
    19 point a[maxn],b[maxn];
    20 //int a[maxn],b[maxn];
    21 int m,n,k,l,d;
    22 bool cmp1(const point a,const point b)
    23 {
    24     return a.num>b.num;
    25 }
    26 bool cmp2(const point a,const point b)
    27 {
    28     return a.id<b.id;
    29 }
    30 int main()
    31 {
    32     while(cin>>m>>n>>k>>l>>d)
    33     {
    34         for(int i=0;i<maxn;i++)
    35         {
    36             a[i].id=b[i].id=i;
    37             a[i].num=b[i].num=0;
    38         }
    39         for(int i=0;i<d;i++)
    40         {
    41             int x,y,p,q,h;
    42             scanf("%d%d%d%d",&x,&y,&p,&q);
    43             if(x==p){
    44                 h=min(y,q);
    45                 b[h].num++;
    46             }
    47             if(y==q)
    48             {
    49                 h=min(x,p);
    50                 a[h].num++;
    51             }
    52         }
    53         sort(a,a+maxn,cmp1);
    54         sort(b,b+maxn,cmp1);
    55         sort(a,a+k,cmp2);
    56         sort(b,b+l,cmp2);
    57         for(int i=0;i<k;i++){
    58             cout<<a[i].id<<" ";
    59         }
    60         cout<<endl;
    61         for(int i=0;i<l;i++)
    62         {
    63             cout<<b[i].id<<" ";
    64         }
    65         cout<<endl;
    66     }
    67     return 0;
    68 }
    View Code
  • 相关阅读:
    转 Java高级程序员面试题
    发个说说0.0
    SpringMvc和servlet对比
    java面试数据类型
    java面试 关键字
    Ajax与传统Web开发的区别
    ssm框架常见问题
    浅谈C++多态性
    [转载]构造函数、析构函数可否声明为虚函数
    为什么不要在构造函数和析构函数中调用虚函数?
  • 原文地址:https://www.cnblogs.com/wolf940509/p/5852706.html
Copyright © 2011-2022 走看看