11.排座椅
2022-11-27 15:38:36
发布于:江苏
362阅读
0回复
0点赞
11.[NOIP2008 普及组] 排座椅
难度:普及-
来源:NOIP提高组
AC & WA代码(C++):
/*
#include <bits/stdc++.h>
using namespace std;
struct A
{
int n,p; // N is used to store the number of people that can be separated, and p is used to store the separated roads
}k[1005],l[1005];
bool cmp(A x,A y)
{
return x.n > y.n;
}
bool cmp1(A x,A y)
{
return x.p < y.p;
}
int d,n,m,p,q,x1,x2,y1,y2,i1 = 0,j1 = 0;
int main(void)
{
cin >> m >> n >> p >> q >> d; // L k is replaced by p q
for (int i = 1;i <= d;i++)
{
cin >> x1 >> y1 >> x2 >> y2;
if (x1 == x2)
{
l[min(y1,y2)].p = min(y1,y2);
l[min(y1,y2)].n++;
}
else
{
k[min(x1,x2)].p = min(x1,x2);
k[min(x1,x2)].n++;
}
} // Simple input+judgment (because the question indicates whether x1==x2 or y1==y2)
sort(l + 1,l + n + 1,cmp);
sort(k + 1,k + m + 1,cmp); // This is greed. Find the way that can separate the largest number of people, and fewer people will talk
sort(l +1 ,l + q + 1,cmp1);
sort(k + 1,k + p + 1,cmp1);
cout << k[1].p;
for (int i = 2;i <= p;i++)
{
cout << " " << k[i].p;
}
cout << endl;
cout << l[1].p;
for (int i = 2;i <= q;i++)
{
cout << " " << l[i].p;
}
cout << endl;
return 0;
}
*/
#include<iostream>
#include<algorithm>
using namespace std;
struct A
{
int n,p;
}k[1005],l[1005];
bool cmp(A x,A y)
{
return x.n>y.n;
}
bool cmp1(A x,A y)
{
return x.p<y.p;
}
int d,n,m,p,q,x1,x2,y1,y2,i1=0,j1=0;
int main()
{
cin>>m>>n>>p>>q>>d;
for(int i=1;i<=d;i++)
{
cin>>x1>>y1>>x2>>y2;
if(x1==x2)
{
l[min(y1,y2)].p=min(y1,y2);
l[min(y1,y2)].n++;
}
else
{
k[min(x1,x2)].p=min(x1,x2);
k[min(x1,x2)].n++;
}
}
sort(l+1,l+n+1,cmp);
sort(k+1,k+m+1,cmp);
sort(l+1,l+q+1,cmp1);
sort(k+1,k+p+1,cmp1);
cout << k[1].p;
for(int i=2;i<=p;i++) cout<<" " <<k[i].p;
cout<<endl;
cout << l[1].p;
for(int i=2;i<=q;i++) cout<<" " <<l[i].p;
cout << endl;
return 0;
}
注释代码为WA代码,下面代码为AC代码,注释在WA代码中。
没有注释,自行学习。
by:ACGO
你的点赞和关注就是我更新题解的最大动力!
-----------------------------点个赞吧 ↓ !-----------------------------
全部评论 3
6
2023-12-24 来自 广东
0lj
2023-08-14 来自 广东
0lj
2023-08-14 来自 广东
0lj
2023-08-14 来自 广东
0
6的一匹
2022-12-16 来自 浙江
0
有帮助,赞一个