Luo Valley P1056 [NOIP2008] seat row

Jump meaning of problems

Very simple greedy problem, apparently for a column or a row, separated by more if we speak of human preference.

Note the order output

 1 #include<cstdio>
 2 #include<iostream>
 3 #include<cstring>
 4 #include<algorithm>
 5 
 6 using namespace std;
 7 
 8 struct node
 9 {
10     int num;
11     int data;
12 };
13 node lie[1005],heng[1005];
14 int n,m,k,l,d;
15 
16 inline bool cmp(node x,node y)
17 {
18     return x.data>y.data;
19 }
20 
21 int main()
22 {
23     scanf("%d%d%d%d%d",&m,&n,&k,&l,&d);
24     for(int i=1;i<=m;i++)
25         heng[i].num=i;
26     for(int i=1;i<=n;i++)
27         lie[i].num=i;
28     for(int i=1;i<=d;++i)
29     {
30         int x1,y1,x2,y2;
31         scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
32         if(x1==x2)
33         {
34             int p=min(y1,y2);
35             lie[p].data++;
36         }
37         else
38         {
39             int p=min(x1,x2);
40             heng[p].data++;
41         }
42     }
43     sort(heng+1,heng+n+1,cmp);
44     int ans_heng[1005];
45     for(int i=1;i<=k;i++)
46         ans_heng[i]=heng[i].num;
47     sort(ans_heng+1,ans_heng+k+1);
48     for(int i=1;i<=k;i++)
49         printf("%d ",ans_heng[i]);
50     printf("\n");
51     sort(lie+1,lie+m+1,cmp);
52     int ans_lie[1005];
53     for(int i=1;i<=l;i++)
54         ans_lie[i]=lie[i].num;
55     sort(ans_lie+1,ans_lie+l+1);
56     for(int i=1;i<=l;i++)
57         printf("%d ",ans_lie[i]);
58     return 0;
59 }
P1056 code

 

Guess you like

Origin www.cnblogs.com/Hoyoak/p/11361003.html