标签:ISE scan scanf can name https int algorithm put
题目大意:
输入k,n ;k为每位慢跑者最少应看到的广告牌数
接下来n行 描述第 i 位慢跑者的途径路段
输出需要设立的广告牌数 接下来每行为设立地点
5 10
1 10
20 27
0 -3
15 15
8 2
7 30
-1 -10
27 20
2 9
14 21
19
-5
-4
-3
-2
-1
0
4
5
6
7
8
15
18
19
20
21
25
26
27
题解:https://blog.csdn.net/shuangde800/article/details/7828537
#include<iostream> #include<algorithm> #include<stdio.h> #include<stdlib.h> #include<cstring> using namespace std; struct num { int a,b; bool operator<(const num& p)const { return b<p.b; }; }jog[1005]; bool vis[20005]; int main() { int n,k; while(~scanf("%d%d",&k,&n)) { int st=20000,ed=0,ans=0; for(int i=0;i<n;i++) { int p,q; scanf("%d%d",&p,&q); jog[i].a=min(p,q)+10000; jog[i].b=max(p,q)+10000; st=min(st,jog[i].a); ed=max(ed,jog[i].b); } sort(jog,jog+n); // for(int i=0;i<n;i++) // printf("%d %d %d\n",jog[i].a-10000,jog[i].b-10000,jog[i].b-jog[i].a); memset(vis,0,sizeof(vis)); for(int i=0;i<n;i++) { int len=jog[i].b-jog[i].a+1; if(len<=k) { for(int j=jog[i].a;j<=jog[i].b;j++) if(!vis[j]) vis[j]=1,ans++; } else { int cnt=0; for(int j=jog[i].a;j<=jog[i].b;j++) if(vis[j]) cnt++; if(cnt>=k) continue; for(int j=jog[i].b;j>=jog[i].a;j--) if(!vis[j]) { vis[j]=1; cnt++; ans++; if(cnt>=k) break; } } } printf("%d\n",ans); for(int i=st;i<=ed;i++) if(vis[i]) printf("%d\n",i-10000); printf("\n"); } return 0; }
NEERC 1999 Advertisement /// oj22646
标签:ISE scan scanf can name https int algorithm put
原文地址:https://www.cnblogs.com/zquzjx/p/8870907.html