【UVALive】3695 Distant Galaxy(......)

 2023-10-18 阅读 22 评论 0

摘要:題目 傳送門:QWQ ? ? 分析 好喵啊~~~~ 不會做 正解看藍書P53吧 ? ? 代碼 #include <cstdio> #include <algorithm> using namespace std; inline int read() {int x = 0, f = 1; char ch = getchar();while (ch < '0' || ch > &

題目

傳送門:QWQ

?

?

分析

好喵啊~~~~

不會做

正解看藍書P53吧

?

?

代碼

#include <cstdio>
#include <algorithm>
using namespace std;
inline int read()
{int x = 0, f = 1; char ch = getchar();while (ch < '0' || ch > '9'){if (ch == '-')f = -1;ch = getchar();}while (ch >= '0' && ch <= '9'){x = x * 10 + ch - '0';ch = getchar();}return x * f;
}
struct Point{int x,y;bool operator < (const  Point& rhs) const{return x<rhs.x;}
};
const int maxn=105;
Point P[maxn]; int n,m,y[maxn],on[maxn],on2[maxn],left[maxn];
int solve(){sort(P,P+n); sort(y,y+n);m=unique(y,y+n)-y;if(m<=2) return n;int ans=0;for(int a=0;a<m;a++)for(int b=a+1;b<m;b++){int ymin=y[a], ymax=y[b];int k=0;for(int i=0;i<n;i++){if(i==0 || P[i].x!=P[i-1].x){k++;on[k]=on2[k]=0;left[k]=k==0?0:left[k-1]+on2[k-1]-on[k-1]; }if(P[i].y>ymin  && P[i].y<ymax) on[k]++;if(P[i].y>=ymin && P[i].y<=ymax) on2[k]++;}if(k<=2) return n;int M=0;for(int j=1;j<=k;j++){ans=max(ans,left[j]+on2[j]+M);M=max(M,on[j]-left[j]);}}return ans;
}
int main(){int kase=0;while(scanf("%d",&n)==1 && n){for(int i=0;i<n;i++){P[i].x=read();P[i].y=read();y[i]=P[i].y;}printf("Case %d: %d\n",++kase,solve());}return 0;
}

?

?

?

轉載于:https://www.cnblogs.com/noblex/p/9225378.html

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/4/149870.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息