Codeforces Round #518 (Div. 2) [Thanks, Mail.Ru!]

https://codeforces.com/contest/1068

A

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define lson l,mid,rt<<1
  4. #define rson mid+1,r,rt<<1|1
  5. #define sqr(x) ((x)*(x))
  6. #define pb push_back
  7. #define eb emplace_back
  8. #define maxn 300005
  9. #define eps 1e-8
  10. #define pi acos(-1.0)
  11. #define rep(k,i,j) for(int k=i;k<j;k++)
  12. typedef long long ll;
  13. typedef pair<int,int> pii;
  14. typedef pair<long long,int>pli;
  15. typedef pair<int,char> pic;
  16. typedef pair<pair<int,string>,pii> ppp;
  17. typedef unsigned long long ull;
  18. const long long mod=1e9+;
  19. /*#ifndef ONLINE_JUDGE
  20. freopen("1.txt","r",stdin);
  21. #endif */
  22.  
  23. int main(){
  24. #ifndef ONLINE_JUDGE
  25. // freopen("1.txt","r",stdin);
  26. #endif
  27. std::ios::sync_with_stdio(false);
  28. ll n,m,k,l;
  29. cin>>n>>m>>k>>l;
  30. if(n<m||n-k<l){
  31. cout<<-<<endl;
  32. return ;
  33. }
  34. ll res=(k+l)/m;
  35. if(res*m<k+l) ++res;
  36. if(res*m<=n) cout<<res<<endl;
  37. else cout<<-<<endl;
  38. }

B

数论

因为lcm(a,b)/a==b/gcd(a,b),又因为b是确定的,所以求的是gcd(a,b)的个数,也就是求b的因子数

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define lson l,mid,rt<<1
  4. #define rson mid+1,r,rt<<1|1
  5. #define sqr(x) ((x)*(x))
  6. #define pb push_back
  7. #define eb emplace_back
  8. #define maxn 300005
  9. #define eps 1e-8
  10. #define pi acos(-1.0)
  11. #define rep(k,i,j) for(int k=i;k<j;k++)
  12. typedef long long ll;
  13. typedef pair<int,int> pii;
  14. typedef pair<long long,int>pli;
  15. typedef pair<int,char> pic;
  16. typedef pair<pair<int,string>,pii> ppp;
  17. typedef unsigned long long ull;
  18. const long long mod=1e9+;
  19. /*#ifndef ONLINE_JUDGE
  20. freopen("1.txt","r",stdin);
  21. #endif */
  22.  
  23. int main(){
  24. #ifndef ONLINE_JUDGE
  25. // freopen("1.txt","r",stdin);
  26. #endif
  27. std::ios::sync_with_stdio(false);
  28. ll n;
  29. cin>>n;
  30. int sq=sqrt(n);
  31. ll ans=;
  32. for(int i=;i<=sq;i++){
  33. ll co=;
  34. while(n%i==){
  35. n/=i;
  36. co++;
  37. }
  38. ans*=co;
  39. }
  40. if(n>) ans*=;
  41. cout<<ans<<endl;
  42. }

C

找规律

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define lson l,mid,rt<<1
  4. #define rson mid+1,r,rt<<1|1
  5. #define sqr(x) ((x)*(x))
  6. #define pb push_back
  7. #define eb emplace_back
  8. #define maxn 300005
  9. #define eps 1e-8
  10. #define pi acos(-1.0)
  11. #define rep(k,i,j) for(int k=i;k<j;k++)
  12. typedef long long ll;
  13. typedef pair<int,int> pii;
  14. typedef pair<long long,int>pli;
  15. typedef pair<int,char> pic;
  16. typedef pair<pair<int,string>,pii> ppp;
  17. typedef unsigned long long ull;
  18. const long long mod=1e9+;
  19. /*#ifndef ONLINE_JUDGE
  20. freopen("1.txt","r",stdin);
  21. #endif */
  22.  
  23. vector<int>ve[];
  24. int n,m;
  25.  
  26. int main(){
  27. #ifndef ONLINE_JUDGE
  28. // freopen("1.txt","r",stdin);
  29. #endif
  30. std::ios::sync_with_stdio(false);
  31. cin>>n>>m;
  32. for(int i=;i<=n;i++){
  33. ve[i].pb(i);
  34. }
  35. int x,y;
  36. int co=n+;
  37. for(int i=;i<m;i++){
  38. cin>>x>>y;
  39. ve[x].pb(co);
  40. ve[y].pb(co);
  41. co++;
  42. }
  43. for(int i=;i<=n;i++){
  44. cout<<ve[i].size()<<endl;
  45. for(int j=;j<ve[i].size();j++){
  46. cout<<i<<" "<<ve[i][j]<<endl;
  47. }
  48. }
  49. }

D

DP

参考博客:https://blog.csdn.net/white_156/article/details/83421537

  1. #include<iostream>
  2. using namespace std;
  3. #define lson l,mid,rt<<1
  4. #define rson mid+1,r,rt<<1|1
  5. #define sqr(x) ((x)*(x))
  6. #define pb push_back
  7. #define eb emplace_back
  8. #define maxn 100005
  9. #define eps 1e-8
  10. #define pi acos(-1.0)
  11. #define rep(k,i,j) for(int k=i;k<j;k++)
  12. typedef long long ll;
  13. typedef pair<int,int> pii;
  14. typedef pair<long long,int>pli;
  15. typedef pair<int,char> pic;
  16. typedef pair<pair<int,string>,pii> ppp;
  17. typedef unsigned long long ull;
  18. const long long mod=;
  19. /*#ifndef ONLINE_JUDGE
  20. freopen("1.txt","r",stdin);
  21. #endif */
  22.  
  23. int a[];
  24. long long dp[][][];
  25.  
  26. int main(){
  27. #ifndef ONLINE_JUDGE
  28. // freopen("1.txt","r",stdin);
  29. #endif
  30. std::ios::sync_with_stdio(false);
  31. int n;
  32. scanf("%d",&n);
  33. for(int i=;i<=n;i++) cin>>a[i];
  34. if(a[]!=-){
  35. dp[][a[]][]=;
  36. }
  37. else{
  38. for(int i=;i<=;i++){
  39. dp[][i][]=;
  40. dp[][i][]=;
  41. }
  42. }
  43. for(int i=;i<=n;i++){
  44. if(a[i]==-){
  45. dp[i][][]=;
  46. for(int j=;j<=;j++)
  47. dp[i][j][]=(dp[i][j][]+dp[i][j-][]+dp[i-][j-][]+dp[i-][j-][])%mod;
  48. dp[i][][]=;
  49. for(int j=;j>=;j--){
  50. dp[i][j][]=(dp[i][j][]+dp[i][j+][]+dp[i-][j+][])%mod;
  51. }
  52. for(int j=;j<=;j++)
  53. dp[i][j][]=(dp[i][j][]+dp[i-][j][]+dp[i-][j][])%mod;
  54. }
  55. else{
  56. int num=a[i];
  57. for(int j=;j<num;j++)
  58. dp[i][num][]=(dp[i][num][]+dp[i-][j][]+dp[i-][j][])%mod;
  59. for(int j=num+;j<=;j++)
  60. dp[i][num][]=(dp[i][num][]+dp[i-][j][])%mod;
  61. dp[i][num][]=(dp[i][num][]+dp[i-][num][]+dp[i-][num][])%mod;
  62. }
  63. }
  64. long long ans=;
  65. for(int i=;i<=;i++)
  66. ans=(ans+dp[n][i][])%mod;
  67. cout<<ans<<endl;
  68.  
  69. }

E

模拟

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define lson l,mid,rt<<1
  4. #define rson mid+1,r,rt<<1|1
  5. #define sqr(x) ((x)*(x))
  6. #define pb push_back
  7. #define eb emplace_back
  8. #define maxn 100005
  9. #define eps 1e-8
  10. #define pi acos(-1.0)
  11. #define rep(k,i,j) for(int k=i;k<j;k++)
  12. typedef long long ll;
  13. typedef pair<int,int> pii;
  14. typedef pair<long long,int>pli;
  15. typedef pair<int,char> pic;
  16. typedef pair<pair<int,string>,pii> ppp;
  17. typedef unsigned long long ull;
  18. const long long mod=;
  19. /*#ifndef ONLINE_JUDGE
  20. freopen("1.txt","r",stdin);
  21. #endif */
  22.  
  23. set<int>se[maxn],v,t;
  24. set<int>::iterator it;
  25. int cnt[maxn];
  26.  
  27. int main(){
  28. #ifndef ONLINE_JUDGE
  29. // freopen("1.txt","r",stdin);
  30. #endif
  31. std::ios::sync_with_stdio(false);
  32. int n,k;
  33. cin>>n>>k;
  34. for(int i=;i<n;i++)
  35. {
  36. int u,v;
  37. cin>>u>>v;
  38. se[u].insert(v);
  39. se[v].insert(u);
  40. }
  41. for(int i=;i<=n;i++)
  42. if(se[i].size()==)
  43. v.insert(i);
  44. while(n>)
  45. {
  46. t.clear();
  47. for(it=v.begin();it!=v.end();it++)
  48. {
  49. int x=*se[*it].begin();
  50. cnt[x]++;
  51. t.insert(x);
  52. se[x].erase(*it);
  53. n--;
  54. }
  55. for(it=t.begin();it!=t.end();it++)
  56. {
  57. if(cnt[*it]<)
  58. {
  59. printf("No\n");
  60. return ;
  61. }
  62. cnt[*it]=;
  63. }
  64. swap(v,t);
  65. k--;
  66. }
  67. if(k==)printf("Yes\n");
  68. else printf("No\n");
  69.  
  70. }

Codeforces Round #518 (Div. 2) [Thanks, Mail.Ru!]的更多相关文章

  1. 【2000*】【Codeforces Round #518 (Div. 1) [Thanks, Mail.Ru!] B】Multihedgehog

    [链接] 我是链接,点我呀:) [题意] [题解] 找到度数为1的点. 他们显然是叶子节点. 然后每个叶子节点. 往上进行bfs. 累计他们的父亲节点的儿子的个数. 如果都满足要求那么就继续往上走. ...

  2. 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 由唯一分解 ...

  3. Codeforces Round #518 (Div. 2) B LCM

    传送门 https://www.cnblogs.com/violet-acmer/p/10163375.html 题解: 这道题有点意思,有点数学的味道. 根据定义“[a,b] / a”可得这求得是l ...

  4. Codeforces Round #518 Div. 1没翻车记

    A:设f[i][j][0/1]为前i个数第i位为j且第i位未满足/已满足限制的方案数.大力dp前缀和优化即可. #include<iostream> #include<cstdio& ...

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

  6. 【Codeforces Round #518 (Div. 2)】

    A:https://www.cnblogs.com/myx12345/p/9847588.html B:https://www.cnblogs.com/myx12345/p/9847590.html ...

  7. Codeforces Round #518 (Div. 1) Computer Game 倍增+矩阵快速幂

    接近于死亡的选手没有水平更博客,所以现在每五个月更一篇. 这道题呢,首先如果已经有权限升级了,那么后面肯定全部选的是 \(p_ib_i\) 最高的. 设这个值为 \(M=\max \limits_i ...

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

  9. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

随机推荐

  1. PHP数据库基于PDO操作类(mysql)

    这是网上找的关于Mysql的操作类,非常适合初学者使用 <?php class Mysql { protected static $_dbh = null; //静态属性,所有数据库实例共用,避 ...

  2. 2319__1.5.3 Superprime Rib 特殊的质数肋骨

    [Submit][Status][Forum] Description 农民约翰母牛总是产生最好的肋骨. 你能通过农民约翰和美国农业部标记在每根肋骨上的数字认出它们. 农民约翰确定他卖给买方的是真正的 ...

  3. AS_简单的开始

    1.注释   单行注释  //           多行注释  /* src */ 2.变量   变量名,可以包含字母.数字.下划线.$.但不以数字开头.   变量类型,是严格数据类型.AS有静态类型 ...

  4. Mac下如何安装WebStorm + 破解

    1.官网下载       下载地址   选择好系统版本以后,点击DOWNLOAD        2.安装 双击下载好的安装包.将WebStromt拖入application文件夹,然后在Launchp ...

  5. 【剑指offer】单链表尾部插入一个节点

    #include <iostream> using namespace std; //链表结构体 struct ListNode { int m_Value; ListNode *next ...

  6. 解决eclipse+adt出现的 loading data for android 问题

    因为公司最近做的项目中有用到一些第三方demo,蛋疼的是这些demo还比较旧...eclipse的... 于是给自己的eclipse装上了ADT插件,但是...因为我的eclipse比较新,Versi ...

  7. (转)关闭win10的Skype

    https://blog.csdn.net/qq_38285661/article/details/86663849 使用win10的小伙伴们,有没有发现一个不用的功能Skype,假如你想卸载又怕卸不 ...

  8. fwrite()中参数含义——size和count经常用搞反

    函数原型:size_t fwrite(const void* buffer, size_t size, size_t count, FILE* stream);   注意:这个函数以二进制形式对文件进 ...

  9. Unity3D之Lightmap详解

    作者:李志健 Unity 完全集成了光照贴图,可以通过编辑器创建完整的光照贴图,你完全不用担心,所有材质会自动获得光照贴图.光照贴图的意思是,所有灯光的特性将被直接映射到Beast lightmapp ...

  10. 吴裕雄 python 爬虫(3)

    import hashlib md5 = hashlib.md5() md5.update(b'Test String') print(md5.hexdigest()) import hashlib ...