codefores 538-C. Tourist's Notes(数学)
来源:互联网 发布:java 动态代理模式 编辑:程序博客网 时间:2024/06/14 01:27
http://codeforces.com/problemset/problem/538/C
题目大意:
在一个组数中给出一些下标固定的数,要求每个相邻的数之间差值为1,问这组数最大值可以是多少?
解题思路:
考虑两个尽头的特殊情况,接着按照2*n-1的公式不断枚举,找出最大值。
#include<iostream>#include<cmath>using namespace std;int main(){ long long n,m,a,b,x,y; while(cin>>n>>m) { cin>>a>>b; long long blag=0,ans=a+b-1,i=1; for(;i<m;i++) { cin>>x>>y; if(blag) continue; if(x-a>=fabs(y-b)) { long long p=x-a,q=fabs(y-b),res=p-q-1,j=1,tt=1; //p表示长度 q表示差值 while(tt<=res) { j++; tt+=2; } ans=max(ans,j-1+max(y,b)); } else blag=1; a=x,b=y; } ans=max(ans,n-a+b); if(blag) cout<<"IMPOSSIBLE"<<endl; else cout<<ans<<endl; } return 0;}
阅读全文
0 0
- codefores 538-C. Tourist's Notes(数学)
- CodeForce 538C Tourist's Notes(贪心 + 数学)
- Code Forces 538 C. Tourist's Notes(贪心)
- CF 538C(Tourist's Notes-贪心)
- CodeForces 538C Tourist's Notes (简单题)
- codeforces #300 C. Tourist's Notes
- [CF538C]Tourist's Notes
- #300 (div.1 2) C. Tourist's Notes
- Codeforces Round #300-Tourist's Notes(贪心)
- Codeforces 340C Tourist Problem 数学+DP
- Codeforces Round #198 (Div. 2) C. Tourist Problem (数学+dp)
- Codefores 460C-Present(二分+贪心)
- codefores 352 C. Recycling Bottles
- C. Tourist Problem
- CodeForces 340C Tourist Problem(组合排列,公式推导)
- Codefores Good Bye 2014 - A,B,C
- codefores #267C George and Job(dp)
- codefores 73C LionAge II (dp)
- Android 通过appt.exe获取已安装apk的版本信息
- MySQL数据文件说明
- born to do
- 详述 IntelliJ IDEA 提交代码前的 Code Analysis 机制
- python selenium-webdriver 处理JS弹出对话框
- codefores 538-C. Tourist's Notes(数学)
- spring mvc文件上传
- wdcp后台访问安全设置即限制域名/IP访问设置及清除方法
- Cocos2d-场景切换-CCTransitionFlipX和CCTransitionFade和CCTransitionSlideInL
- 关于z-index层级问题
- JavaWeb之DBUtils(一)QueryRunner类对数据表的增、删、查(8种结果集处理方式)、改操作
- 动态链接时出现undefined symbol错误
- 经常出门的男人赶紧收藏起来,太实用了
- 记录一下