当前位置:网站首页>P1056 row seats (greedy & sort)

P1056 row seats (greedy & sort)

2021-08-10 08:05:10 wx6110fa547fd20

P1056 Row seats ( greedy & Sort )

  Subject portal

Ideas : Calculate the logarithm of each row and column separately , Then sort , Take... Separately k and l Just one .

#include<bits/stdc++.h>
using namespace std;
const int N=1e3+5; 
struct p{
	int id,v;
}a[N],b[N];
bool cmp(p a,p b){
	return a.v>b.v;
}
int vis[N][2];
int main(){
	int n,m,k,l,d;
	cin>>n>>m>>k>>l>>d;
	for(int i=1,x1,y1,x2,y2;i<=d;i++){
		 cin>>x1>>y1>>x2>>y2;
		 if(y1==y2) a[min(x1,x2)].v++,a[min(x1,x2)].id=min(x1,x2);//printf("a[%d]",min(x1,x2));
		 else b[min(y1,y2)].v++,b[min(y1,y2)].id=min(y1,y2);//printf("b[%d]",min(y1,y2));
	}
	sort(a+1,a+N,cmp);
	sort(b+1,b+N,cmp);
	for(int i=1;i<=l;i++)
		vis[b[i].id][1]=1;
		for(int i=1;i<=k;i++)
		vis[a[i].id][0]=1;
	for(int i=1,j=1;i<n;i++)
			if(vis[i][0])
			printf(j++==k?"%d\n":"%d ",i);
	for(int i=1,j=1;i<m;i++)
			if(vis[i][1])
			printf(j++==l?"%d\n":"%d ",i);		
	return 0;	
} 

      
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.

版权声明
本文为[wx6110fa547fd20]所创,转载请带上原文链接,感谢
https://chowdera.com/2021/08/20210810080205621r.html

随机推荐