首页 > 代码库 > 繁华模拟赛 旅行者的笔记
繁华模拟赛 旅行者的笔记
#include<iostream>#include<cstdio>#include<string>#include<cstring>#include<algorithm>#include<cmath>using namespace std;const int maxn = 100005;int n,m,cnt,d[maxn],h[maxn];int main(){ freopen("note.in","r",stdin); freopen("note.out","w",stdout); cin>>n>>m; for(int i = 1;i <= m;i++){ scanf("%d%d",&d[i],&h[i]); } int ans = max(h[m] + n - d[m],h[1] + d[1] - 1); int hg,lw,div,mid; for(int i = 2;i <= m;i++){ div = h[i] - h[i-1]; if(div < 0) div = -div; if(div > d[i]-d[i-1]){ cout<<"IMPOSSIBLE"; return 0; } mid = (h[i] + h[i-1] + d[i] - d[i-1]) >> 1; ans = max(ans,mid); } cout<<ans; return 0;}#include<cstdio>#include<iostream>#include<algorithm>#include<cstring>#include<cmath>#include<vector>#include<queue>#include<map>#include<set>#include<stack>#include<cstdlib>#include<string>#include<bitset>#define INF 200000000#define N 100005#define fi first#define se second#define debug(x) cout<<#x<<"="<<x<<endl#define MP(x,y) make_pair(x,y)using namespace std;typedef long long LL;typedef pair<int,int> pii;int a[N],b[N];int main(){ int n,m,ans=0,flag,t,l,r,mid,x,now,i; freopen("note.in","r",stdin); freopen("note.out","w",stdout); cin>>n>>m; for(i=1;i<=m;i++) { scanf("%d%d",&a[i],&b[i]); if(i==1) ans=b[i]+a[i]-1; else { t=a[i]-a[i-1]; x=b[i]-b[i-1]; if(abs(x)>t) { printf("IMPOSSIBLE\n"); return 0; } x=abs(x); ans=max(ans,max(b[i],b[i-1])); l=0,r=INF; now=0; while(l<=r) { mid=(l+r)>>1; if(mid+abs(mid-x)<=t) now=mid,l=mid+1; else r=mid-1; } ans=max(ans,min(b[i],b[i-1])+now); } if(i==m) ans=max(ans,b[i]+n-a[i]); } cout<<ans<<endl; return 0;}// davidlee1999WTK 2015/// srO myk Orz//ios::sync_with_stdio(false);/*100 110 10*/
繁华模拟赛 旅行者的笔记
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。