首页 > 学院 > 开发设计 > 正文

CodeForces Round #403 补题

2019-11-06 06:26:36
字体:
来源:转载
供稿:网友

PRoblem A :

#include <cstdio>#include <iostream>#include <cstring>using namespace std;#define F(i,a,b) for(int i=a;i<=b;i++)#define maxn 100005int main(){ int n,num[2*maxn]; scanf("%d",&n); F(i,1,2*n) scanf("%d",&num[i]); int count=0,res=0,vis[maxn]; memset(vis, 0, sizeof(vis)); F(i,1,2*n){ if(vis[num[i]]==0){ vis[num[i]]=1; count++; }else{ count--; } res = max(res, count); } cout<<res<<endl; return 0;}

Problem B :

这题刚开始没有什么思路,后来想通了是用二分查找,注意在STL库里面max 和 min比较double,尾数越多比较的时间越长,选择 1e-7 才不容易TLE

#include <iostream>#include <cstdio>using namespace std;const double eps=1e-7;#define maxn 60005#define F(i,a,b) for(int i=a;i<=b;i++)int n,x[maxn],v[maxn],sum;bool check(double m){ double b=-2e9,t=2e9; F(i,1,n){ b = max(b,x[i]-v[i]*m); t = min(t,x[i]+v[i]*m); } return b<=t;}int main(){ sum =0; scanf("%d",&n); F(i,1,n) {scanf("%d",&x[i]);sum+=x[i];} F(i,1,n) scanf("%d",&v[i]); double L=0,R=1e9,M; while((R-L)>=eps){ M = (L+R)/2.0; if(check(M)) R=M; else L=M; } printf("%.9lf/n",(L+R)/2.0); return 0;}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表