Codeforces ECR50 div2题解
A:签到
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
ll read()
{
ll x=,f=;char c=getchar();
while (c<''||c>'') {if (c=='-') f=-;c=getchar();}
while (c>=''&&c<='') x=(x<<)+(x<<)+(c^),c=getchar();
return x*f;
}
ll n,k;
int main()
{
n=read(),k=read();
cout<<(k-)/n+;
return ;
}
B:大讨论。想清楚的话可以写的更优美一点。
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
int read()
{
int x=,f=;char c=getchar();
while (c<''||c>'') {if (c=='-') f=-;c=getchar();}
while (c>=''&&c<='') x=(x<<)+(x<<)+(c^),c=getchar();
return x*f;
}
int n;
int main()
{
n=read();
for (int i=;i<=n;i++)
{
long long x,y,k,ans=-;
cin>>x>>y>>k;
if (x>y) swap(x,y);
if (k>=x)
{
if (x==y) ans=((k&)==(x&))?k:k-;
else
{
ans=x;k-=x;y-=x;
if (k<y) ans=-;
else
{
if (y%==)
{
if (k&) ans+=k-;
else ans+=k;
}
else ans+=k-;
}
}
}
cout<<ans<<endl;
}
return ;
}
C:大力数位dp。还可以把所有合法数都找出来然后二分找答案。
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
int read()
{
int x=,f=;char c=getchar();
while (c<''||c>'') {if (c=='-') f=-;c=getchar();}
while (c>=''&&c<='') x=(x<<)+(x<<)+(c^),c=getchar();
return x*f;
}
int n,a[];
long long C(int n,int m)
{
if (m<) return ;
if (m==) return ;
if (m==) return n;
if (m==) return n*(n-)/;
if (m==) return n*(n-)*(n-)/;
}
long long calc(long long x)
{
int n=,cnt=;
long long ans=;
memset(a,,sizeof(a));
while (x) a[++n]=x%,x/=;
for (int i=n;i;i--)
if (a[i])
{
if (cnt<=) ans++;
if (cnt<=) ans+=*C(i-,);
if (cnt<=) ans+=**C(i-,);
if (cnt<=) ans+=***C(i-,);
cnt++;
if (cnt<=) ans+=a[i]-;
if (cnt<=) ans+=(a[i]-)**C(i-,);
if (cnt<=) ans+=(a[i]-)***C(i-,);
}
if (cnt<=) ans++;
return ans;
}
int main()
{
n=read();
for (int i=;i<=n;i++)
{
long long x,y;
cin>>x>>y;
cout<<calc(y)-calc(x-)<<endl;
}
return ;
}
D:B题难度。双指针移动,若匹配上则ans++。
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
int read()
{
int x=,f=;char c=getchar();
while (c<''||c>'') {if (c=='-') f=-;c=getchar();}
while (c>=''&&c<='') x=(x<<)+(x<<)+(c^),c=getchar();
return x*f;
}
#define N 300010
int n,m,ans=;
long long a[N],b[N];
int main()
{
n=read();
for (int i=;i<=n;i++) a[i]=read()+a[i-];
m=read();
for (int i=;i<=m;i++) b[i]=read()+b[i-];
int x=;
for (int i=;i<=n;i++)
{
while (x<=m&&a[i]>b[x]) x++;
if (x>m) {ans=-;break;}
if (a[i]==b[x]) ans++;
}
if (a[n]!=b[m]) ans=-;
if (x<m) ans=-;
cout<<ans;
return ;
}
E:gcd一下求出线段上整点数量再暴力算交点去重即可。没有写,据说很卡精度。
F:可以发现所求的就是存在k>1,k∈N*使开k次方为整数的数。可以算出有多少个能开k次方的数,然后用莫比乌斯函数容斥。开方直接用pow再微调一下。
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
ll read()
{
ll x=,f=;char c=getchar();
while (c<''||c>'') {if (c=='-') f=-;c=getchar();}
while (c>=''&&c<='') x=(x<<)+(x<<)+(c^),c=getchar();
return x*f;
}
#define N 110
int T,prime[N],mobius[N],cnt=;
bool flag[N];
ll calc(ll n,int k)
{
ll a=pow(n,(long double)/k);
ll s=;
for (int i=;i<=k;i++)
{
if (s>n/(a+)) break;
s=s*(a+);
if (i==k&&s<=n) return a+;
}
return a;
}
int main()
{
flag[]=;mobius[]=;
for (int i=;i<=;i++)
{
if (!flag[i]) prime[++cnt]=i,mobius[i]=-;
for (int j=;prime[j]*i<=&&j<=cnt;j++)
{
flag[prime[j]*i]=;
if (i%prime[j]==) break;
mobius[prime[j]*i]=-mobius[i];
}
}
T=read();
while (T--)
{
ll n=read(),ans=;
for (int i=;i<=;i++)
if (mobius[i]) ans+=mobius[i]*(calc(n,i)-);
printf("%I64d\n",ans);
}
return ;
}
G:如果图是强连通的,那么图中每个点都在某些源到汇的路径上。于是只要源和汇之间相互可达就可以了。用这个性质直接随机的话据说错误率只有1e-8。
当然考虑靠谱的做法。注意到源汇的个数很少,考虑枚举源子集,验证其是否可能与剩下部分不在同一SCC内(当然枚举的子集不包括全集)。
源子集对应了一个汇子集。那么显然若汇子集大小不大于源子集,则可以将汇的出边全部连向该源子集,剩下部分无法与其强连通。
上述检验没有考虑子集内部是否可以连接至强连通。不过在枚举该子集的子集时这种情况已经被检验。
Codeforces ECR50 div2题解的更多相关文章
- codeforces #275 div2题解
A题大意: 给你l,r,问你在l~r之间,是否存在 a和b互质 , b和c互质 ,但是 a,c不互质 的情况:其中l<=a<b<c<=r;如果存在,就输出a,b,c;不存在就输 ...
- Codeforces 1323 div2题解ABC
A. Even Subset Sum Problem 签到题 #include <bits/stdc++.h> using namespace std; template <type ...
- Codeforces Round #707 Editorial Div2 题解
CF1501 Div2 题解 CF1501A 这道题其实是一道英语阅读题,然后样例解释又不清晰,所以我看了好久,首先它告诉了你每个站点的预期到达时间 \(a_i\) ,以及每个站点的预期出发时间 \( ...
- Codeforces #541 (Div2) - E. String Multiplication(动态规划)
Problem Codeforces #541 (Div2) - E. String Multiplication Time Limit: 2000 mSec Problem Descriptio ...
- Codeforces #541 (Div2) - F. Asya And Kittens(并查集+链表)
Problem Codeforces #541 (Div2) - F. Asya And Kittens Time Limit: 2000 mSec Problem Description Inp ...
- Codeforces #541 (Div2) - D. Gourmet choice(拓扑排序+并查集)
Problem Codeforces #541 (Div2) - D. Gourmet choice Time Limit: 2000 mSec Problem Description Input ...
- Codeforces #548 (Div2) - D.Steps to One(概率dp+数论)
Problem Codeforces #548 (Div2) - D.Steps to One Time Limit: 2000 mSec Problem Description Input Th ...
- Codeforces #180 div2 C Parity Game
// Codeforces #180 div2 C Parity Game // // 这个问题的意思被摄物体没有解释 // // 这个主题是如此的狠一点(对我来说,),不多说了这 // // 解决问 ...
- Codeforces Round #556 题解
Codeforces Round #556 题解 Div.2 A Stock Arbitraging 傻逼题 Div.2 B Tiling Challenge 傻逼题 Div.1 A Prefix S ...
随机推荐
- 使用Java线程并发库实现两个线程交替打印的线程题
背景:是这样的今天在地铁上浏览了以下网页,看到网上一朋友问了一个多线程的问题.晚上闲着没事就决定把它实现出来. 题目: 1.开启两个线程,一个线程打印A-Z,两一个线程打印1-52的数据. 2.实现交 ...
- 'utf-8' codec can't decode byte 0xbc in position 1182: invalid start byte
2.如果是字符集出现错误,建议多选择几种字符集测试一下: 选择的经验是: 如果是爬取到的网页文件,可以查看网页文件的meta标签下的charset属性值.例如: <meta charset=&q ...
- setInterval() 方法应用
setInterval() 方法可按照指定的周期(以毫秒计)来调用函数或计算表达式. setInterval() 方法会不停地调用函数,直到 clearInterval() 被调用或窗口被关闭.由 s ...
- 【转】python直接运行tcl脚本
python中调用tcl是通过加载TkInter来实现的. from Tkinter import Tcl tcl = Tcl() tcl.eval('source tu.tcl') tcl.eval ...
- C/C++函数调用方式
__cdecl __fastcall与__stdcall,三者都是调用约定(Calling convention),它决定以下内容:1)函数参数的压栈顺序,2)由调用者还是被调用者把参数弹出栈,3)以 ...
- Linux rhel7 无线网络配置
前言: 手提新装rhel7, ifconfig 发现只有lo 怎么办? 1. 检查网卡驱动装了没有: nmcli -a|grep wlp\ 如果没安装: a. lspci|grep Wireless ...
- 移动端页面滑动时候警告:Unable to preventDefault inside passive event listener due to target being treated as passive.
移动端项目中,在滚动的时候,会报出以下提示: [Intervention] Unable to preventDefault inside passive event listener due to ...
- Sleeping会话导致阻塞原理(上)
背景 我在处理客户问题的时候,客户经常搞不懂sleeping 的由来,和他可能导致的问题.下面来详细说下 什么是sleeping 其实我们经常可以在数据库中看到“”sleeping“状态的连接,但是这 ...
- pandas 初识(三)
Python Pandas 空值 pandas 判断指定列是否(全部)为NaN(空值) import pandas as pd import numpy as np df = pd.DataFrame ...
- es6箭头函数使用场景导致的一些问题
1. 今天在使用draggable组件时,监听dragmove事件时获取到的事件对象有一些异常, 代码如下 draggable.on('drag:move', (event) => { cons ...