Educational Codeforces Round 50
1036A - Function Height 20180907
\(ans=\left \lceil \frac{k}{n} \right \rceil\)
#include<bits/stdc++.h>
using namespace std;
#define LL long long
LL n,k;
int main()
{
scanf("%I64d%I64d",&n,&k);
printf("%I64d\n",(k-)/n+);
return ;
}
1036B - Diagonal Walking v.2 20180907
简单分类讨论即可
#include<bits/stdc++.h>
using namespace std;
#define N 10001
#define LL long long
LL q,n,m,k;
int main()
{
scanf("%I64d",&q);
while(q--)
{
scanf("%I64d%I64d%I64d",&n,&m,&k);
if(max(n,m)>k){printf("-1\n");continue;}
printf("%I64d\n",n+m&?k-:(k+m&?k-:k));
}
}
1036C - Classy Numbers 20180907
暴力预处理出所有满足条件的数,排序后去重即可
#include<bits/stdc++.h>
using namespace std;
#define LL long long
LL T,l,r,cnt,p[],f[];
int main()
{
p[]=,f[++cnt]=1000000000000000000ll;
for(LL i=;i<;i++)p[i]=p[i-]*10ll;
for(LL i=;i<=;i++)
{
LL x=i/,y=(i/)%,z=i%;
for(LL a=;a<;a++)
for(LL b=;b<;b++)if(b!=a)
for(LL c=;c<;c++)if(c!=b && c!=a)
f[++cnt]=x*p[a]+y*p[b]+z*p[c];
}
sort(f+,f+cnt+);
cnt=unique(f+,f+cnt+)-f-;
scanf("%I64d",&T);
while(T--)
{
scanf("%I64d%I64d",&l,&r);
printf("%I64d\n",(LL)(upper_bound(f+,f+cnt+,r)-lower_bound(f+,f+cnt+,l)));
}
}
1036D - Vasya and Arrays 20180907
预处理两个数组的前缀和,当且仅当\(a_n=b_m\)时有解,答案就是\(a_i=b_j\)的方案数
#include<bits/stdc++.h>
using namespace std;
#define N 300005
#define LL long long
LL n,m,a[N],b[N],ans;
int main()
{
scanf("%I64d",&n);
for(LL i=;i<=n;i++)
scanf("%I64d",&a[i]),a[i]+=a[i-];
scanf("%I64d",&m);
for(LL i=;i<=m;i++)
scanf("%I64d",&b[i]),b[i]+=b[i-];
if(a[n]!=b[m])return printf("-1\n"),;
LL i=,j=;
while(i<=n && j<=m)
{
while(a[i]<b[j] && i<=n)i++;
while(b[j]<a[i] && j<=m)j++;
if(i<=n && j<=m && a[i]==b[j])
i++,ans++;
}
printf("%I64d\n",ans);
return ;
}
1036E - Covered Points 20180907
首先,若设一个线段对应的向量是(x,y),则这个线段上的整点数量为gcd(x,y)+1,之后考虑把相交的整点部分去除就好了
注意判断交点是否为整点时,不建议直接强转成整型,否则可能会有精度损失(比如可能会将2记录为1.99999999,强制转换后会变为1)
前方超长代码预警,学长的模板真是太好用了xD
#include<bits/stdc++.h>
using namespace std;
typedef long double lod;
typedef long long ll;
typedef long double ld;
const ld eps=1e-;
const ld pi=acos(-1.0);
int sgn(ld x)
{
if (x<-eps) return -;
if (x>eps) return ;
return ;
} struct P; //点,向量
struct LINE; //线段,射线,直线;
struct CIRCLE;
struct TRIANGLE;
struct POLYGON; void kr(ld &x)
{
double t; scanf("%lf",&t);
x=t;
}
void kr(ll &x)
{
scanf("%I64d",&x);
}
struct P
{
lod x,y;
void read()
{
kr(x); kr(y);
}
P operator+(const P &t)const
{
return {x+t.x,y+t.y};
}
P operator-(const P &t)const
{
return {x-t.x,y-t.y};
}
P operator*(ld t)const
{
return {x*t,y*t};
}
P operator/(ld t)const
{
return {x/t,y/t};
}
lod operator*(const P &t)const
{
return x*t.y-y*t.x;
} //叉积
lod operator%(const P &t)const
{
return x*t.x+y*t.y;
} //点积
bool operator<(const P &t)const
{
return sgn(x-t.x)<||sgn(x-t.x)==&&sgn(y-t.y)<;
}
bool operator==(const P &t)const
{
return sgn(x-t.x)==&&sgn(y-t.y)==;
}
ld ang()const
{
return atan2(y,x);
}
ld length()const
{
return sqrt(x*x+y*y);
}
P rotate(const P &t,ld sita)const
{
return {(x-t.x)*cos(sita)-(y-t.y)*sin(sita)+t.x,
(x-t.x)*sin(sita)+(y-t.y)*cos(sita)+t.y};
} //逆时针转sita
ld btang(const P &t)const
{
return acos( (*this%t)/length()/t.length() );
} //向量夹角
P midvec(const P &t)const
{
return (*this)/length()+t/t.length();
} //角平分向量
}; struct LINE
{
P p1,p2;
void read()
{
p1.read(); p2.read();
}
LINE midLINE()
{
P midp=(p1+p2)/;
P v=p2-p1;
v=v.rotate({,},pi/);
return {midp,midp+v};
} //中垂线
bool have1(const P &p)const
{
return sgn( (p-p1)*(p-p2) )==&&sgn( (p-p1)%(p-p2) )<=;
} //线段上有点
bool have2(const P &p)const
{
return sgn( (p-p1)*(p-p2) )==&&sgn( (p-p1)%(p2-p1) )>=;
} //射线上有点
bool have3(const P &p)const
{
return sgn( (p-p1)*(p-p2) )==;
} //直线上有点
lod areawith(const P &p)const
{
return abs( (p1-p)*(p2-p)/ );
} //线段和点围成面积
P vecfrom(const P &p)const
{
P v=(p2-p1);
v=v.rotate({,},pi/);
ld s1=(p1-p)*(p2-p);
ld s2=v*(p2-p1);
v=v*(s1/s2);
return v;
}//点到直线垂足的向量
P footfrom(const P &p)const
{
P v=vecfrom(p);
return p+v;
} //点到直线垂足
ld dis1from(const P &p)const
{
P foot=footfrom(p);
if (have1(foot)) return (foot-p).length();
return min( (p1-p).length(),(p2-p).length());
}//点到线段距离
ld dis2from(const P &p)const
{
P foot=footfrom(p);
if (have2(foot)) return (foot-p).length();
return (p1-p).length();
}//点到射线距离
ld dis3from(const P &p)const
{
return vecfrom(p).length();
}//点到直线距离
P symP(const P &p)const
{
P v=vecfrom(p);
return p+v*;
} //点关于直线的对称点 //1线段 2射线 3直线
bool isct11(const LINE &L)const
{
P a1=p1,a2=p2;
P b1=L.p1,b2=L.p2;
if (sgn( max(a1.x,a2.x)-min(b1.x,b2.x) )<||
sgn( max(b1.x,b2.x)-min(a1.x,a2.x) )<||
sgn( max(a1.y,a2.y)-min(b1.y,b2.y) )<||
sgn( max(b1.y,b2.y)-min(a1.y,a2.y) )<)
return ;
lod tmp1=(a2-a1)*(b1-a1);
lod tmp2=(a2-a1)*(b2-a1);
if (sgn(tmp1)<&&sgn(tmp2)<||sgn(tmp1)>&&sgn(tmp2)>) return ;
tmp1=(b2-b1)*(a1-b1);
tmp2=(b2-b1)*(a2-b1);
if (sgn(tmp1)<&&sgn(tmp2)<||sgn(tmp1)>&&sgn(tmp2)>) return ;
return ;
}
//前提是不重合且有交点,p1沿p2-p1方向到达L上的长度,负数表示反向
//直线交多边形需要用到
ld dis33(const LINE &L)const
{
return (L.p1-p1)*(L.p2-p1) / ( (p2-p1)*(L.p2-L.p1) )
* (p2-p1).length();
}
P isctPoint(const LINE &L)const
{
ld len=dis33(L);
P v=p2-p1;
return p1+v*(len/v.length());
}
};
ll n,x,y,z,w,ans;
LINE a[];
map<pair<ll,ll>,set<ll> >f;
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
bool check(lod k){return fabs(k-round(k))<eps;}
#define mp make_pair
int main()
{
kr(n);
for(ll i=;i<=n;i++)
{
kr(x),kr(y),kr(z),kr(w);
ll dx=abs(z-x),dy=abs(w-y);
ans+=gcd(dx,dy)+;
a[i]={{(lod)x,(lod)y},{(lod)z,(lod)w}};
}
for(ll i=;i<=n;i++)
for(ll j=i+;j<=n;j++)
if(a[i].isct11(a[j]))
{
P p=a[i].isctPoint(a[j]);
if(check(p.x) && check(p.y))
f[mp(round(p.x),round(p.y))].insert(i),
f[mp(round(p.x),round(p.y))].insert(j);
}
for(auto x:f)ans-=(ll)x.second.size()-;
printf("%I64d\n",ans);
return ;
}
1036F - Relatively Prime Powers 20180907
考虑预处理不满足条件的数,设\(k_i\)的gcd值为K,显然当一个数x对应的K>1时,有\(x=m^{K}\),这里m为大于1的整数。因此我们可以发现其实不满足条件的数就是满足\(x=m^{K}\)的数x的集合,其中m,K均为大于1的整数。由于n的范围是1e18,所以可以暴力预处理K>2的情况,并把可以表示为平方数的数暂时去掉,之后排序再去重一下就好了。
代码中的Sqrt是为了防止精读误差写的,以前被坑过 于是后来较大的数开方就都这么写了_(:з」∠)_
#include<bits/stdc++.h>
using namespace std;
#define LL long long
LL T,n,cnt,f[];
LL Sqrt(LL k)
{
LL x=sqrt(k);
while(x*x<k)x++;
while(x*x>k)x--;
return x;
}
bool check(LL k)
{
LL x=Sqrt(k);
return x*x<k;
}
int main()
{
LL N=1000000000000000000ll;
for(LL i=;i<=;i++)
{
LL b=i*i;
while(b<=N/i)
{
b*=i;
if(check(b))
f[++cnt]=b;
}
}
sort(f+,f+cnt+);
cnt=unique(f+,f+cnt+)-f-;
scanf("%I64d",&T);
while(T--)scanf("%I64d",&n),printf("%I64d\n",n-(LL)(upper_bound(f+,f+cnt+,n)-f-)-Sqrt(n));
return ;
}
1036G - Sources and Sinks 20180908
显然原图联通等价于由源点和汇点组成的图联通,考虑源点的集合X,X中源点能到达的汇点的集合为Y,可以发现若|Y|<=|X|,则答案一定是NO。遍历所有源点的子集(空集和全集)即可
#include<bits/stdc++.h>
using namespace std;
#define N 1000001
int n,m,u,v,k,I[N],O[N];
vector<int>d[N],t;
bool x[][N];
set<int>s;
void dfs(int k,int cur)
{
x[k][cur]=true;
for(auto nxt:d[cur])
if(!x[k][nxt])dfs(k,nxt);
}
int main()
{
scanf("%d%d",&n,&m);
for(int i=;i<=m;i++)
scanf("%d%d",&u,&v),
d[u].push_back(v),
I[v]++,O[u]++;
for(int i=;i<=n;i++)
{
if(!I[i])dfs(k++,i);
if(!O[i])t.push_back(i);
}
for(int i=;i<(<<k)-;i++)
{
s.clear();
int cnt=;
for(int j=;j<k;j++)
if(i&(<<j))
{
cnt++;
for(auto nxt:t)
if(x[j][nxt])s.insert(nxt);
}
if(s.size()<=cnt)return printf("NO\n"),;
}
return printf("YES\n"),;
}
Educational Codeforces Round 50的更多相关文章
- Educational Codeforces Round 50 (Rated for Div. 2) F - Relatively Prime Powers(数学+容斥)
题目链接:http://codeforces.com/contest/1036/problem/F 题意: 题解:求在[2,n]中,x != a ^ b(b >= 2 即为gcd)的个数,那么实 ...
- Educational Codeforces Round 50 (Rated for Div. 2) C. Classy Numbers
C. Classy Numbers 题目链接:https://codeforces.com/contest/1036/problem/C 题意: 给出n个询问,每个询问给出Li,Ri,问在这个闭区间中 ...
- Educational Codeforces Round 50 (Rated for Div. 2)的A、B、C三题AC代码
A题链接:https://codeforces.com/contest/1036/problem/A A题AC代码: #include <stdio.h> #include <std ...
- Educational Codeforces Round 50 (Rated for Div. 2)F. Relatively Prime Powers
实际上就是求在[2,n]中,x != a^b的个数,那么实际上就是要求x=a^b的个数,然后用总数减掉就好了. 直接开方求和显然会有重复的数.容斥搞一下,但实际上是要用到莫比乌斯函数的,另外要注意减掉 ...
- Educational Codeforces Round 50 (Rated for Div. 2) E. Covered Points
注释上都有解析了,就不写了吧,去重的问题就用set解决,并且呢第i个线段最多和其他线段产生i-1个交点,n^2logn. #include <cmath> #include <cst ...
- Educational Codeforces Round 5
616A - Comparing Two Long Integers 20171121 直接暴力莽就好了...没什么好说的 #include<stdlib.h> #include&l ...
- Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings
Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings 题目连接: http://cod ...
- Educational Codeforces Round 63 (Rated for Div. 2) 题解
Educational Codeforces Round 63 (Rated for Div. 2)题解 题目链接 A. Reverse a Substring 给出一个字符串,现在可以对这个字符串进 ...
- Educational Codeforces Round 22 E. Army Creation
Educational Codeforces Round 22 E. Army Creation 题意:求区间[L,R]内数字次数不超过k次的这些数字的数量的和 思路:和求区间内不同数字的数量类似,由 ...
随机推荐
- 【转】http的keep-alive和tcp的keepalive区别
http://blog.csdn.net/oceanperfect/article/details/51064574 1.HTTP Keep-Alive在http早期,每个http请求都要求打开一个t ...
- CSS魔法堂:display:none与visibility:hidden的恩怨情仇
前言 还记得面试时被问起"请说说display:none和visibility:hidden的区别"吗?是不是回答完display:none不占用原来的位置,而visibilit ...
- SharePoint PowerShell 修改母版页
前言 最近在群里帮忙回答问题,碰到这么一个尴尬的问题,有人创建了一个新母版页,然后引用了新的母版页,不知道怎么的母版页有问题了,再也进不去站点了,希望修改回旧的母版页. 看到问题,想了一下,其实两种方 ...
- 修复恢复"可疑"的SQLServer数据库
今天机房突然断电,DB连不上了,提示 无法打开数据库'MyDB'.恢复操作已将该数据库标记为 SUSPECT. 原因是断电导致DB文件损坏 通过SQL Server Management Studio ...
- ABAP技术总结
SAP ——ABAP/4 技术总结 V3.0 2014-10-14 --江正军 1. 1.1. 1.1.1. 1.2. 1.3. 1.4. 1.5. 1.6. 1.7. 1.7.1. 1.7.2. ...
- 【MySQL】解决You can't specify target table 'user_cut_record_0413' for update in FROM clause
问题 You can't specify target table 'user_cut_record_0413' for update in FROM clause 原因 待更新/删除的数据集与查询的 ...
- python接口自动化测试(五)-其它(认证&代理&超时配置)
有了前面几节的介绍,基本的接口测试是可以满足了.本节一些其它的高级技巧: 一.认证 1.基本认证: # -*- coding:utf-8 -*- import requests url = " ...
- Node.js模板引擎的深入探讨
每次当我想用 node.js 来写一个 web 相关项目的时候.我总是会陷入无比的纠结.原因是 JavaScript 生态圈里的模板引擎实在太多了,但那么多却实在找不出一个接近完美的,所谓完美的概念就 ...
- PHP中一些常用知识点
1.json字符串转json对象 $data='[{"user_id":"93","price":"52.50"},{& ...
- java字符串的替换replace、replaceAll、replaceFirst的区别详解
如果不是刚刚复习了下正则表达式,我可能也不会注意到,原来String的replaceAll跟replaceFirst用到了正则表达式! 不多解释,看代码: String s = "my.te ...