Codeforces Beta Round #67 (Div. 2)

http://codeforces.com/contest/75

A

 #include<bits/stdc++.h>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define sqr(x) ((x)*(x))
#define pb push_back
#define eb emplace_back
#define maxn 1000006
#define eps 1e-8
#define pi acos(-1.0)
#define rep(k,i,j) for(int k=i;k<j;k++)
typedef long long ll;
typedef unsigned long long ull; int main(){
#ifndef ONLINE_JUDGE
// freopen("input.txt","r",stdin);
#endif
std::ios::sync_with_stdio(false);
int a,b,c;
cin>>a>>b;
c=a+b;
int ccc=;
int aa=,bb=,cc;
int p=;
while(a){
int tmp=a%;
if(tmp!=){
aa+=(tmp)*p;
p*=;
}
a/=;
}
p=;
while(b){
int tmp=b%;
if(tmp!=){
bb+=(tmp)*p;
p*=;
}
b/=;
}
p=;
while(c){
int tmp=c%;
if(tmp!=){
ccc+=(tmp)*p;
p*=;
}
c/=;
}
cc=aa+bb;
if(cc==ccc) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}

B

模拟

 #include<bits/stdc++.h>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define sqr(x) ((x)*(x))
#define pb push_back
#define eb emplace_back
#define maxn 1000006
#define eps 1e-8
#define pi acos(-1.0)
#define rep(k,i,j) for(int k=i;k<j;k++)
typedef long long ll;
typedef unsigned long long ull; int main(){
#ifndef ONLINE_JUDGE
// freopen("input.txt","r",stdin);
#endif
std::ios::sync_with_stdio(false);
string me;
cin>>me;
int n;
cin>>n;
map<string,int>M,S{{"posted",},{"commented",},{"likes",}};
for(string a,b,c,x;cin>>a>>b>>c>>x;M[a],M[c])
{
if(c=="on")c=x,cin>>x;
c.pop_back();c.pop_back();
if(a==me)M[c]+=S[b];
if(c==me)M[a]+=S[b];
}
vector<pair<int,string>>V;
for(map<string,int>::iterator it=M.begin();it!=M.end();it++)V.emplace_back(-it->second,it->first);
sort(V.begin(),V.end());
for(int i=;i<V.size();i++)if(V[i].second!=me)cout<<V[i].second<<endl;
}

C

二分+gcd

 #include<bits/stdc++.h>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define sqr(x) ((x)*(x))
#define pb push_back
#define eb emplace_back
#define maxn 1000006
#define eps 1e-8
#define pi acos(-1.0)
#define rep(k,i,j) for(int k=i;k<j;k++)
typedef long long ll;
typedef unsigned long long ull; int aa,bb,l,r,x,y;
int a[]; int main(){
#ifndef ONLINE_JUDGE
// freopen("input.txt","r",stdin);
#endif
std::ios::sync_with_stdio(false);
cin>>aa>>bb;
int n;
cin>>n;
int gcd=__gcd(aa,bb);
int co=;
int gg=sqrt(gcd);
a[co++]=;
for(int i=;i<=gg;i++){
if(gcd%i==){
a[co++]=i;
if(gcd/i!=gg){
a[co++]=gcd/i;
}
}
}
a[co++]=gcd;
sort(a+,a+co);
int mid;
for(int i=;i<=n;i++){
cin>>x>>y;
l=,r=co-;
while(l<=r){
mid=l+r>>;
if(a[mid]<=y) l=mid+;
else {
r=mid-;
}
}
if(a[r]>y) r--;
if(a[r]>=x&&a[r]<=y) cout<<a[r]<<endl;
else cout<<-<<endl;
}
}

D

应该是最大子段和的加强版吧,把最大前缀和,最大后缀和,最大子区间和求出来,然后找最大值

 #include<bits/stdc++.h>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define sqr(x) ((x)*(x))
#define pb push_back
#define eb emplace_back
#define maxn 1000006
#define eps 1e-8
#define pi acos(-1.0)
#define rep(k,i,j) for(int k=i;k<j;k++)
typedef long long ll;
typedef unsigned long long ull; ll maxl[],maxr[],sum[],dp[],Right; int main(){
#ifndef ONLINE_JUDGE
// freopen("input.txt","r",stdin);
#endif
std::ios::sync_with_stdio(false);
int n,m;
cin>>n>>m;
int num;
int x;
for(int i=;i<=n;i++){
cin>>num;
maxl[i]=dp[i]=-0x3f3f3f3f;
Right=;
for(int j=;j<=num;j++){
cin>>x;
sum[i]+=x;
maxl[i]=max(sum[i],maxl[i]);
Right+=x;
dp[i]=max(dp[i],Right);
if(Right<) Right=;
}
maxr[i]=Right;
}
ll ans=-0x3f3f3f3f;
Right=;
for(int i=;i<=m;i++){
cin>>x;
ans=max(max(ans,dp[x]),Right+maxl[x]);
Right=max(Right+sum[x],maxr[x]);
}
cout<<ans<<endl;
}

E

几何,分类讨论即可

 #include<bits/stdc++.h>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define sqr(x) ((x)*(x))
#define pb push_back
#define eb emplace_back
#define maxn 1000006
#define eps 1e-8
#define pi acos(-1.0)
#define rep(k,i,j) for(int k=i;k<j;k++)
typedef long long ll;
typedef unsigned long long ull; struct Point{
double x,y;
}a[],h[],s,e;
double ans;
int p[],n,m; double dis(Point a, Point b) {
return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
} double cross(Point s, Point a, Point b) {
return (a.x - s.x) * (b.y - s.y) - (b.x - s.x) * (a.y - s.y);
} void check(Point a, Point b, Point c, Point d, int i) {
double t1 = cross(a, c, b), t2 = cross(a, b, d), t3 = cross(c, a, d), t4 = cross(c, d, b);
if (fabs(t1) < eps && fabs(t2) < eps) return ;
if (fabs(dis(a, c) + dis(c, b) - dis(a, b)) < eps) {
h[m] = c; p[m] = i; ++m; return ;
}
if (t1 * t2 > eps && t3 * t4 > eps) {
h[m].x = (t1 * d.x + t2 * c.x) / (t1 + t2);
h[m].y = (t1 * d.y + t2 * c.y) / (t1 + t2);
p[m] = i; ++m;
}
} double getl(int st, int en, int x, int y) {
double res; st = (st + ) % n; res = ;
for (int i = st; i != en; i = (i + ) % n)
res += dis(a[i], a[(i + ) % n]);
return res + dis(h[x], a[st]) + dis(a[en], h[y]);
} int main(){
#ifndef ONLINE_JUDGE
// freopen("input.txt","r",stdin);
#endif
// std::ios::sync_with_stdio(false);
cin>>s.x>>s.y>>e.x>>e.y>>n;
for (int i = ; i < n; ++i) cin>>a[i].x>>a[i].y;
for (int i = ; i < n; ++i) check(s, e, a[i], a[(i + ) % n], i);
if (m == ) {
if (dis(s, h[]) > dis(s, h[])) swap(h[], h[]), swap(p[], p[]);
ans = min(getl(p[], p[], , ), getl(p[], p[], , ));
ans = min(ans, dis(h[], h[]) * );
ans += dis(s, h[]) + dis(h[], e);
}
else ans = dis(s, e);
printf("%.7f\n",ans);
}

Codeforces Beta Round #67 (Div. 2)的更多相关文章

  1. 【计算几何】 Codeforces Beta Round #67 (Div. 2) E. Ship's Shortest Path

    读懂题意其实是模板题.就是细节略多. #include<cstdio> #include<cmath> #include<algorithm> using name ...

  2. Codeforces Beta Round #67 (Div. 2)C. Modified GCD

    C. Modified GCD time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...

  3. Codeforces Beta Round #80 (Div. 2 Only)【ABCD】

    Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...

  4. Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】

    Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...

  5. Codeforces Beta Round #79 (Div. 2 Only)

    Codeforces Beta Round #79 (Div. 2 Only) http://codeforces.com/contest/102 A #include<bits/stdc++. ...

  6. Codeforces Beta Round #77 (Div. 2 Only)

    Codeforces Beta Round #77 (Div. 2 Only) http://codeforces.com/contest/96 A #include<bits/stdc++.h ...

  7. Codeforces Beta Round #76 (Div. 2 Only)

    Codeforces Beta Round #76 (Div. 2 Only) http://codeforces.com/contest/94 A #include<bits/stdc++.h ...

  8. Codeforces Beta Round #75 (Div. 2 Only)

    Codeforces Beta Round #75 (Div. 2 Only) http://codeforces.com/contest/92 A #include<iostream> ...

  9. Codeforces Beta Round #74 (Div. 2 Only)

    Codeforces Beta Round #74 (Div. 2 Only) http://codeforces.com/contest/90 A #include<iostream> ...

随机推荐

  1. PHP提取HTML代码中img标签下src属性

    需求:提取整片文章中img的src属性,并保存到一个数组当中 preg_match_all("/(href|src)=([\"|']?)([^\"'>]+.(jpg ...

  2. redis内部数据结构和外部数据结构揭秘

    Redis有哪些数据结构? 字符串String.字典Hash.列表List.集合Set.有序集合SortedSet. 很多人面试时都遇到过这种场景吧? 其实除了上面的几种常见数据结构,还需要加上数据结 ...

  3. node.js 爬虫动态代理ip

    参考文章: https://andyliwr.github.io/2017/12/05/nodejs_spider_ip/ https://segmentfault.com/q/10100000081 ...

  4. 机器学习入门-数值特征-进行二值化变化 1.Binarizer(进行数据的二值化操作)

    函数说明: 1. Binarizer(threshold=0.9) 将数据进行二值化,threshold表示大于0.9的数据为1,小于0.9的数据为0 对于一些数值型的特征:存在0还有其他的一些数 二 ...

  5. css下拉导航栏代码

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  6. echarts图表--统计图表

    echarts官网图表API:http://echarts.baidu.com/index.html

  7. preparedstatement 为什么可以防止sql注入

    有大神总结的很好,,参考文献 http://www.importnew.com/5006.html preparedstatement优势:sql的预编译(数据库层面完成)提升效率. 为什么可以防止s ...

  8. Windows命令行打开常用界面

    本文主要介绍Windows下命令行操作打开常用界面,使用方法为在DOS命令行下输入相关命令.可以减少多次操作界面.可以尝试在命令行执行下面提到的命令感受下,快捷键主要内容包括: 1.查看计算机的基本信 ...

  9. java Run to Line

    在运行Java代码时, 选择运行  Run AS java ,  出现    java Run to Line, 是因为程序还在运行,没有停止.在控制,点击右键.terminate  结束,在Run ...

  10. 记Dagger2使用过程中的一个BUG--compileGoogleDebugJavaWithJavac

    项目编译可以通过,不过没有生成Dagger2的类,导致无法运行项目.. 错误提示 Error:(14, 41) 错误: 找不到符号 符号: 类 DaggerAppComponent 位置: 程序包 c ...