Codeforces Round #518 (Div. 2) [Thanks, Mail.Ru!]
Codeforces Round #518 (Div. 2) [Thanks, Mail.Ru!]
https://codeforces.com/contest/1068
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 300005
#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 pair<int,int> pii;
typedef pair<long long,int>pli;
typedef pair<int,char> pic;
typedef pair<pair<int,string>,pii> ppp;
typedef unsigned long long ull;
const long long mod=1e9+;
/*#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
#endif */ int main(){
#ifndef ONLINE_JUDGE
// freopen("1.txt","r",stdin);
#endif
std::ios::sync_with_stdio(false);
ll n,m,k,l;
cin>>n>>m>>k>>l;
if(n<m||n-k<l){
cout<<-<<endl;
return ;
}
ll res=(k+l)/m;
if(res*m<k+l) ++res;
if(res*m<=n) cout<<res<<endl;
else cout<<-<<endl;
}
B
数论
因为lcm(a,b)/a==b/gcd(a,b),又因为b是确定的,所以求的是gcd(a,b)的个数,也就是求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 300005
#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 pair<int,int> pii;
typedef pair<long long,int>pli;
typedef pair<int,char> pic;
typedef pair<pair<int,string>,pii> ppp;
typedef unsigned long long ull;
const long long mod=1e9+;
/*#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
#endif */ int main(){
#ifndef ONLINE_JUDGE
// freopen("1.txt","r",stdin);
#endif
std::ios::sync_with_stdio(false);
ll n;
cin>>n;
int sq=sqrt(n);
ll ans=;
for(int i=;i<=sq;i++){
ll co=;
while(n%i==){
n/=i;
co++;
}
ans*=co;
}
if(n>) ans*=;
cout<<ans<<endl;
}
C
找规律
#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 300005
#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 pair<int,int> pii;
typedef pair<long long,int>pli;
typedef pair<int,char> pic;
typedef pair<pair<int,string>,pii> ppp;
typedef unsigned long long ull;
const long long mod=1e9+;
/*#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
#endif */ vector<int>ve[];
int n,m; int main(){
#ifndef ONLINE_JUDGE
// freopen("1.txt","r",stdin);
#endif
std::ios::sync_with_stdio(false);
cin>>n>>m;
for(int i=;i<=n;i++){
ve[i].pb(i);
}
int x,y;
int co=n+;
for(int i=;i<m;i++){
cin>>x>>y;
ve[x].pb(co);
ve[y].pb(co);
co++;
}
for(int i=;i<=n;i++){
cout<<ve[i].size()<<endl;
for(int j=;j<ve[i].size();j++){
cout<<i<<" "<<ve[i][j]<<endl;
}
}
}
D
DP
参考博客:https://blog.csdn.net/white_156/article/details/83421537
#include<iostream>
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 100005
#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 pair<int,int> pii;
typedef pair<long long,int>pli;
typedef pair<int,char> pic;
typedef pair<pair<int,string>,pii> ppp;
typedef unsigned long long ull;
const long long mod=;
/*#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
#endif */ int a[];
long long dp[][][]; int main(){
#ifndef ONLINE_JUDGE
// freopen("1.txt","r",stdin);
#endif
std::ios::sync_with_stdio(false);
int n;
scanf("%d",&n);
for(int i=;i<=n;i++) cin>>a[i];
if(a[]!=-){
dp[][a[]][]=;
}
else{
for(int i=;i<=;i++){
dp[][i][]=;
dp[][i][]=;
}
}
for(int i=;i<=n;i++){
if(a[i]==-){
dp[i][][]=;
for(int j=;j<=;j++)
dp[i][j][]=(dp[i][j][]+dp[i][j-][]+dp[i-][j-][]+dp[i-][j-][])%mod;
dp[i][][]=;
for(int j=;j>=;j--){
dp[i][j][]=(dp[i][j][]+dp[i][j+][]+dp[i-][j+][])%mod;
}
for(int j=;j<=;j++)
dp[i][j][]=(dp[i][j][]+dp[i-][j][]+dp[i-][j][])%mod;
}
else{
int num=a[i];
for(int j=;j<num;j++)
dp[i][num][]=(dp[i][num][]+dp[i-][j][]+dp[i-][j][])%mod;
for(int j=num+;j<=;j++)
dp[i][num][]=(dp[i][num][]+dp[i-][j][])%mod;
dp[i][num][]=(dp[i][num][]+dp[i-][num][]+dp[i-][num][])%mod;
}
}
long long ans=;
for(int i=;i<=;i++)
ans=(ans+dp[n][i][])%mod;
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 100005
#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 pair<int,int> pii;
typedef pair<long long,int>pli;
typedef pair<int,char> pic;
typedef pair<pair<int,string>,pii> ppp;
typedef unsigned long long ull;
const long long mod=;
/*#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
#endif */ set<int>se[maxn],v,t;
set<int>::iterator it;
int cnt[maxn]; int main(){
#ifndef ONLINE_JUDGE
// freopen("1.txt","r",stdin);
#endif
std::ios::sync_with_stdio(false);
int n,k;
cin>>n>>k;
for(int i=;i<n;i++)
{
int u,v;
cin>>u>>v;
se[u].insert(v);
se[v].insert(u);
}
for(int i=;i<=n;i++)
if(se[i].size()==)
v.insert(i);
while(n>)
{
t.clear();
for(it=v.begin();it!=v.end();it++)
{
int x=*se[*it].begin();
cnt[x]++;
t.insert(x);
se[x].erase(*it);
n--;
}
for(it=t.begin();it!=t.end();it++)
{
if(cnt[*it]<)
{
printf("No\n");
return ;
}
cnt[*it]=;
}
swap(v,t);
k--;
}
if(k==)printf("Yes\n");
else printf("No\n"); }
Codeforces Round #518 (Div. 2) [Thanks, Mail.Ru!]的更多相关文章
- 【2000*】【Codeforces Round #518 (Div. 1) [Thanks, Mail.Ru!] B】Multihedgehog
[链接] 我是链接,点我呀:) [题意] [题解] 找到度数为1的点. 他们显然是叶子节点. 然后每个叶子节点. 往上进行bfs. 累计他们的父亲节点的儿子的个数. 如果都满足要求那么就继续往上走. ...
- Codeforces Round #518 (Div. 2) B. LCM gcd+唯一分解定律
题意:给出b 求lcm(a,b)/a 在b从1-1e18有多少个不同得结果 思路lcm*gcd=a*b 转换成 b/gcd(a,b) 也就是看gcd(a,b)有多少个值 可以把b 由唯一分解 ...
- Codeforces Round #518 (Div. 2) B LCM
传送门 https://www.cnblogs.com/violet-acmer/p/10163375.html 题解: 这道题有点意思,有点数学的味道. 根据定义“[a,b] / a”可得这求得是l ...
- Codeforces Round #518 Div. 1没翻车记
A:设f[i][j][0/1]为前i个数第i位为j且第i位未满足/已满足限制的方案数.大力dp前缀和优化即可. #include<iostream> #include<cstdio& ...
- Codeforces Round #518 (Div. 2) D(计数DP)
#include<bits/stdc++.h>using namespace std;const long long mod=998244353;int n;int a[100007];l ...
- 【Codeforces Round #518 (Div. 2)】
A:https://www.cnblogs.com/myx12345/p/9847588.html B:https://www.cnblogs.com/myx12345/p/9847590.html ...
- Codeforces Round #518 (Div. 1) Computer Game 倍增+矩阵快速幂
接近于死亡的选手没有水平更博客,所以现在每五个月更一篇. 这道题呢,首先如果已经有权限升级了,那么后面肯定全部选的是 \(p_ib_i\) 最高的. 设这个值为 \(M=\max \limits_i ...
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
随机推荐
- 机器学习实战之朴素贝叶斯进行文档分类(Python 代码版)
贝叶斯是搞概率论的.学术圈上有个贝叶斯学派.看起来吊吊的.关于贝叶斯是个啥网上有很多资料.想必读者基本都明了.我这里只简单概括下:贝叶斯分类其实就是基于先验概率的基础上的一种分类法,核心公式就是条件概 ...
- Redis String数据类型
get() del() set() setnx():如果key 不存在就进行设置,存在返回0 setex():设置value存在时间 setex color 10 red 在10s中,colo ...
- js 编写一个神奇的四则运算
写一个算法,有时候可以用简单的方法就可以写出来,但是只能针对特定的环境,如果要能够适应不同的环境,就需要对算法进行优化,在优化的过程中,你会觉得非常神奇,下面来看一个简单的四则运算的算法编写方式: 1 ...
- 使用Docker搭建Tomcat运行环境
1 准备宿主系统 准备一个 CentOS 7操作系统,具体要求如下: 必须是 64 位操作系统 建议内核在 3.8 以上 通过以下命令查看您的 CentOS 内核: # uname -r 2 安装Do ...
- Visual Studio配置C/C++-PostgreSQL(9.6.3)开发环境(ZT)
https://www.2cto.com/database/201707/658910.html 开发环境 Visual Studio 2017[15.2(26430.16)] PostgreSQL ...
- JavaScript 从定义到执行,你应该知道的那些事
JavaScript从定义到执行,JS引擎在实现层做了很多初始化工作,因此在学习JS引擎工作机制之前,我们需要引入几个相关的概念:执行环境栈.执行环境.全局对象.变量对象.活动对象.作用域和作用域链等 ...
- LeetCode OJ 93. Restore IP Addresses
题目 Given a string containing only digits, restore it by returning all possible valid IP address comb ...
- maven ,添加加密算法,使用
1:消息摘要:(数字指纹):既对一个任意长度的一个数据块进行计算,产生一个唯一指纹.MD5/SHA1发送给其他人你的信息和摘要,其他人用相同的加密方法得到摘要,最后进行比较摘要是否相同. MD5(Me ...
- git-02 下载代码
- swift杂记
1.0 数据类型强转 范围小 --->范围大 不会丢失精度 : 范围大 ---> 范围小 ,可能丢失精度 如 :Int(4.2) = 4 :CGFloat(2) = 2.0 2. ...