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的更多相关文章

  1. 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)的个数,那么实 ...

  2. Educational Codeforces Round 50 (Rated for Div. 2) C. Classy Numbers

    C. Classy Numbers 题目链接:https://codeforces.com/contest/1036/problem/C 题意: 给出n个询问,每个询问给出Li,Ri,问在这个闭区间中 ...

  3. 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 ...

  4. Educational Codeforces Round 50 (Rated for Div. 2)F. Relatively Prime Powers

    实际上就是求在[2,n]中,x != a^b的个数,那么实际上就是要求x=a^b的个数,然后用总数减掉就好了. 直接开方求和显然会有重复的数.容斥搞一下,但实际上是要用到莫比乌斯函数的,另外要注意减掉 ...

  5. Educational Codeforces Round 50 (Rated for Div. 2) E. Covered Points

    注释上都有解析了,就不写了吧,去重的问题就用set解决,并且呢第i个线段最多和其他线段产生i-1个交点,n^2logn. #include <cmath> #include <cst ...

  6. Educational Codeforces Round 5

    616A - Comparing Two Long Integers    20171121 直接暴力莽就好了...没什么好说的 #include<stdlib.h> #include&l ...

  7. 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 ...

  8. Educational Codeforces Round 63 (Rated for Div. 2) 题解

    Educational Codeforces Round 63 (Rated for Div. 2)题解 题目链接 A. Reverse a Substring 给出一个字符串,现在可以对这个字符串进 ...

  9. Educational Codeforces Round 22 E. Army Creation

    Educational Codeforces Round 22 E. Army Creation 题意:求区间[L,R]内数字次数不超过k次的这些数字的数量的和 思路:和求区间内不同数字的数量类似,由 ...

随机推荐

  1. ios之animateWithDuration的坑

    [UIView animateWithDuration:<#(NSTimeInterval)#> delay:<#(NSTimeInterval)#> options:< ...

  2. [DevExpress使用随笔]之NavBarControl控件(一)【转】

    https://blog.csdn.net/HXC_HUANG/article/details/78614092 NavBarControl是具有可扩展组的侧导航控件.一.在Winform窗口中拖入N ...

  3. 【jQuery:遍历同样class的全部值,遍历某一列td的值】

    jsp代码: Html代码 <c:forEach var="main" items="${mainPage.list }"> <tr> ...

  4. git强制修改注释

    在一些公司项目中,常常要求git注释提交的时候加上前缀,比如JIRA号,但是有的时候我们常常会忘了 如果用source tree等一些工具,会推送到本地仓库一半,但远程又上不去. 这个时候我们就需要强 ...

  5. python读取excel(xlrd)

     一.安装xlrd模块: 1.mac下打开终端输入命令: pip install xlrd 2.验证安装是否成功: 在mac终端输入 python  进入python环境 然后输入 import xl ...

  6. javascript umd esm slim

    在CDN的连接中看到多个连接时如何选择? JavaScript 模块现状 UMD和ECMAScript模块 https://cdn.bootcss.com/popper.js/1.13.0/esm/p ...

  7. Java编译过程(传送门)

    我不是要做一门编程语言,了解这个对我现在的工作也没什么帮助,纯粹好奇而已. 传送门

  8. NOIP2011普及组 数字反转

    题目OJ链接: http://codevs.cn/problem/1130/ https://www.luogu.org/problemnew/show/P1307 2011年NOIP全国联赛普及组 ...

  9. Tomcat 部署多个项目出现错误

    有时,我们会遇到部署同样项目可是不同版本号来回切换的问题.可是有时就是莫名奇异的会起不来. 也没太多时间去解决这些问题,所以就又一次把纯净版的Tomcat部署进去就能够了. 我想非常有可能就是Tomc ...

  10. MySQL server has gone away 的两个最常见的可能性

    [背景] 今天测试同学反馈他们docker中的测试库时不时就就报“MySQL server has gone away”,事态之紧急搞的我都有点怕了(像我这么成熟稳重 的DBA怎么有可能怕呢): 第一 ...