Educational Codeforces Round 15(简单题)
来源:互联网 发布:ambari web 源码编译 编辑:程序博客网 时间:2024/06/06 13:04
A. Maximum Increase
题意:
给出一个数列(n<100000),问最长连续上升子序列?
#include<bits/stdc++.h>using namespace std;typedef long long ll;const int N=1e5+9;int a[N];int main(){ int n;scanf("%d",&n); int maxn=1; for(int i=1;i<=n;i++)scanf("%d",&a[i]); a[0]=0; int t=0; for(int i=1;i<=n;i++){ if(a[i]>a[i-1])t++; else maxn=max(maxn,t),t=1; } maxn=max(maxn,t); printf("%d\n",maxn); return 0;}
B. Powers of Two
题目:
给一个数列(n<100000),问符合ai+aj是2的幂次(i< j)的有几对?
#include<bits/stdc++.h>using namespace std;typedef long long ll;const int N=1e5+9;int a[N];int main(){ int n;scanf("%d",&n); map<int,int>mp; for(int i=0;i<n;i++){ scanf("%d",&a[i]); mp[a[i]]++; } ll ans=0; for(int i=0;i<n;i++){ mp[a[i]]--; for(int j=0;j<32;j++){ int x=(1<<j)-a[i]; ans+=mp[x]; } } printf("%I64d\n",ans); return 0;}
C. Cellular Network
题意:
有n个城市,城市位置是ai,有m个信号塔,在bi,距离信号塔r范围之内的城市可以被覆盖,问覆盖所有城市的最小r是多少?a和b序列都是不下降序列。
分析:
二分答案,然后判断r是否可以覆盖所有城市。
在判断某个城市是否可以被覆盖的时候,二分找出离他最近的信号塔,然后判断即可。
#include<bits/stdc++.h>using namespace std;typedef long long ll;const int N=1e5+9;int a[N];int n,m,b[N];bool ismax(int x){ for(int i=0;i<n;i++){ int k=lower_bound(b,b+m,a[i])-b; //cout<<k<<endl; if(k>0&&b[k-1]+x>=a[i]&&b[k-1]-x<=a[i])continue; if(k<m-1&&b[k+1]+x>=a[i]&&b[k+1]-x<=a[i])continue; if(k>=0&&k<m&&b[k]+x>=a[i]&&b[k]-x<=a[i])continue; return false; } return true;}int main(){ //freopen("f.txt","r",stdin); scanf("%d%d",&n,&m); for(int i=0;i<n;i++)scanf("%d",&a[i]); for(int i=0;i<m;i++)scanf("%d",&b[i]); int l=0,r=2e9; while(l<r){ int m=l+(r-l)/2; if(ismax(m))r=m; else l=m+1; } printf("%d\n",l); return 0;}
D. Road to Post Office
题意:
一个人开车去公司,距离是d公里,每次开车可以行使k公里后就坏了,修车需要t秒,开车行驶一公里需要a秒,走路需要b秒,a< b。问到公司需要的最少时间?
分析:
因为a< b,所以刚开始一定是开车的,加入k公里后没到公司,那么就需要决策是否修车或者直接走路了。
这题要注意用long long。中间自己在这里坑了一次。
#include<bits/stdc++.h>using namespace std;typedef long long ll;typedef pair<int,int>pii;const int INF=0x3f3f3f3f;const int N=1e5+9;ll d,k,a,b,t;int main(){ cin>>d>>k>>a>>b>>t; double x=1.0*t/k+a; ll ans=0,ans0=0; //走路 ll kk=k,dd=d; while(dd>0&&kk>0)ans0+=a,dd--,kk--; ans0+=dd*b; //继续开车 kk=k; while(d>0&&kk>0)ans+=a,d--,kk--; ll n=d/k; ans+=n*t+a*n*k; n=d%k; //剩下最后一段距离,选择开车还是走路? ll a1=b*n; ll a2=t+n*a; printf("%I64d\n",min(ans0,min(a1,a2)+ans)); return 0;}
E. Analysis of Pathes in Functional Graph
比赛的时候毫无思路,另写一篇吧QAQ
0 0
- Educational Codeforces Round 15(简单题)
- Educational Codeforces Round 15
- Educational Codeforces Round 15
- Educational Codeforces Round 15
- Educational Codeforces Round 15
- Educational Codeforces Round 15
- Educational Codeforces Round 15
- CF Educational Codeforces Round 15(C)
- Educational Codeforces Round 5-C. The Labyrinth(简单dfs)
- Educational Codeforces Round 15 7.29
- CF Educational Codeforces Round 15(A~D)
- Educational Codeforces Round 15 C. Cellular Network(二分)
- Educational Codeforces Round 15 B. Powers of Two (数学)
- Educational Codeforces Round 15 C. Cellular Network (二分)
- Educational Codeforces Round 15 C Cellular Network(二分)
- Educational Codeforces Round 26 D (dp好题)
- 【解题报告】Educational Codeforces Round 15
- Educational Codeforces Round 15 C. Cellular Network
- LightOJ 1078
- [Python]网络爬虫(二):利用urllib2通过指定的URL抓取网页内容
- composer的安装与使用
- Java 8: Streams API
- Aizu 0189
- Educational Codeforces Round 15(简单题)
- POJ 2377
- 16-07-31 Cannot refer to the non-final local variable homePageInfo defined in an enclosing scope
- 学习写makefile
- 程序员喜欢的9款最佳的Linux文件比较工具
- NOJ 1031 建筑群最长坡值 简单dp
- POJ 1151
- Struts2中的constant配置详解
- HDU 5776 sum