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. C# Activator

    需要动态的创建一个实例模型的时候,就用Activator.CreateInstance(Type type);如果是明确的知道要创建哪个实例的模型,就可以用 new C#在类工厂中动态创建类的实例,所 ...

  2. iOS:Gif动画功能(显示gif动画、获取gif动画时长、获取gif动画执行次数)

    一.简单介绍 gif动画是iOS开发中很常用的一个功能,有的是为了显示加载视频的过程,更多的是为了显示一个结果状态(动画更直观). 那么如何执行gif动画,方法有很多.(这里只写一下方法三,前两种之前 ...

  3. C# Parallel.Invoke 实现

    Parallel.Invoke应该是Parallel几个方法中最简单的一个了,我们来看看它的实现,为了方法大家理解,我尽量保留源码中的注释: public static class Parallel ...

  4. 通过命令“du–sk”, “du–Ask” 的区别,谈谈如何在有保护的文件系统中查看文件或文件夹的大小

    我们都知道,在Windows中,右键单击一个文件或文件夹,选属性(Properties)可以看到这个文件或文件夹的大小.而这个大小是文件的原始大小,即逻辑大小(logical size).即一个1KB ...

  5. 【UML】Java代码与UML模型相互转换方法

    最近重温了一下设计模式,看到大家的博客里面都是Java代码+UML视图,UML表达整体框架,然后再秀出具体的代码,点面结合.一目了然.所以也研究了一下Java代码与UML模型相互转换方法. 一.常用的 ...

  6. codevs 2033 邮票

    洛谷 P2725 邮票 Stamps codevs 2033 邮票 题目链接 http://codevs.cn/problem/2033/ https://www.luogu.org/problemn ...

  7. Java之Servlet

    Servlet规范了JavaWeb项目的结构Servlet的规范约束了服务器如何来实现Servlet规范,如何解析JavaWeb项目的结构. Java就是通过接口来约束 Servlet规范的jar就在 ...

  8. Elasticsearch模糊查询

    前缀查询 匹配包含具有指定前缀的项(not analyzed)的字段的文档.前缀查询对应 Lucene 的 PrefixQuery . 案例 GET /_search { "query&qu ...

  9. Linux端口转发-rinted工具部署、配置、使用

    编者按: 近期由于公司开启定制项目规划,对于每个项目都会开启一个测试服务器,实施方会用到测试服务器的ssh端口.mysql端口.web端口,为了节省资源(公网IP.服务器资源复用),基于rinted工 ...

  10. Python装饰器用法

    在Python中,装饰器一般用来修饰函数,实现公共功能,达到代码复用的目的.在函数定义前加上@xxxx,然后函数就注入了某些行为,很神奇!然而,这只是语法糖而已. 场景 假设,有一些工作函数,用来对数 ...