C

给一个图,并且在边上放上多米诺骨牌,使得每个多米诺骨牌指向的顶点的数字是一致的,并且每种骨牌只能用一种。问最多能够覆盖多少条边。

先生成每一个点指向的数字,然后判断就好了。

  1. #include<cstdio>
  2. #include<cstring>
  3. #include<algorithm>
  4. #include<iostream>
  5. #include<queue>
  6. #include<cmath>
  7. #include<map>
  8. #include<stack>
  9. #include<set>
  10. #include<bitset>
  11. using namespace std;
  12. typedef long long ll;
  13. typedef unsigned long long ull;
  14. typedef pair<int, int> pii;
  15. #define pb(x) push_back(x)
  16. #define cls(x, val) memset(x, val, sizeof(x))
  17. #define fi first
  18. #define se second
  19. #define mp(x, y) make_pair(x, y)
  20. #define inc(i, l, r) for(int i=l; i<=r; i++)
  21. const int inf = 0x3f3f3f3f;
  22. const int maxn = 2000+10;
  23. int n, m;
  24. int l[maxn], r[maxn];
  25. bool vis[11][11];
  26. //数组开小了,然后就会不断的覆盖。。。
  27. int domi[8];
  28. int ans;
  29. void check(){
  30. int tot = 0;
  31. cls(vis, 0);
  32. for(int i=1; i<=m; i++){
  33. int a = domi[l[i]], b=domi[r[i]];
  34. if(a>b) swap(a, b);
  35. if(!vis[a][b]){
  36. vis[a][b] = true;
  37. tot++;
  38. }
  39. }
  40. if(tot>ans) ans = tot;
  41. //cout<<"---"<<ans<<endl;
  42. }
  43. void dfs(int dep){
  44. if(dep>n){
  45. check();
  46. return ;
  47. }
  48. for(int i=1; i<=6; i++){
  49. domi[dep] = i;
  50. dfs(dep+1);
  51. }
  52. }
  53. int main(){
  54. ios::sync_with_stdio(false);
  55. cin>>n>>m;
  56. ans = 0;
  57. for(int i=1; i<=m; i++){
  58. cin>>l[i]>>r[i];
  59. }
  60. dfs(1);
  61. cout<<ans<<endl;
  62. return 0;
  63. }

D

找两个及以上的人去覆盖就可以了。

时间复杂度\(O(n^2)\)

  1. #include<cstdio>
  2. #include<cstring>
  3. #include<algorithm>
  4. #include<iostream>
  5. #include<queue>
  6. #include<cmath>
  7. #include<map>
  8. #include<stack>
  9. #include<set>
  10. #include<bitset>
  11. #include <unordered_map>
  12. using namespace std;
  13. typedef long long ll;
  14. typedef unsigned long long ull;
  15. typedef pair<int, int> pii;
  16. #define pb(x) push_back(x)
  17. #define cls(x, val) memset(x, val, sizeof(x))
  18. #define fi first
  19. #define se second
  20. #define mp(x, y) make_pair(x, y)
  21. #define inc(i, l, r) for(int i=l; i<=r; i++)
  22. const int inf = 0x3f3f3f3f;
  23. const int maxn = 7000+10;
  24. int n;
  25. int idx;
  26. ll a[maxn];
  27. ll c[maxn];
  28. ll b[maxn];
  29. int val[maxn];
  30. ll ans = 0;
  31. unordered_map<ll, int> num;
  32. int main(){
  33. ios::sync_with_stdio(false);
  34. cin>>n;
  35. for(int i=1; i<=n; i++){
  36. cin>>a[i];
  37. num[a[i]]++;
  38. if(num[a[i]]>=2) {
  39. c[++idx] = a[i];
  40. }
  41. }
  42. for(int i=1; i<=n; i++) cin>>b[i];
  43. for(int i=1; i<=idx; i++){
  44. for(int j=1; j<=n; j++){
  45. //i覆盖了j
  46. if((c[i]&a[j]) == a[j]) val[j] = 1;
  47. }
  48. }
  49. for(int i=1; i<=n; i++) ans += (val[i]*b[i]);
  50. cout<<ans<<endl;
  51. return 0;
  52. }

E

有一个结论,若干个数字的gcd,不同的个数为\(O(log(n))\)的级别,使得这道题目的map的常数较小。

  1. #include<cstdio>
  2. #include<cstring>
  3. #include<algorithm>
  4. #include<iostream>
  5. #include<queue>
  6. #include<cmath>
  7. #include<map>
  8. #include<stack>
  9. #include<set>
  10. #include<bitset>
  11. #include <unordered_map>
  12. using namespace std;
  13. typedef long long ll;
  14. typedef unsigned long long ull;
  15. typedef pair<int, int> pii;
  16. #define pb(x) push_back(x)
  17. #define cls(x, val) memset(x, val, sizeof(x))
  18. #define fi first
  19. #define se second
  20. #define mp(x, y) make_pair(x, y)
  21. #define inc(i, l, r) for(int i=l; i<=r; i++)
  22. const int inf = 0x3f3f3f3f;
  23. const int maxn = 2e5+10;
  24. const int mod = 1e9+7;
  25. ll a[maxn];
  26. vector<int> G[maxn];
  27. int n;
  28. unordered_map<ll, int> mp[maxn];
  29. ll ans;
  30. void dfs(int u, int fa){
  31. for(auto &it:mp[fa]){
  32. //更新前面的节点到u节点的权值和。
  33. ll temp = __gcd(it.fi, a[u]);
  34. mp[u][temp]+=(it.se)%mod;
  35. ans = (ans + (temp*it.se%mod))%mod;
  36. }
  37. //更新自己到自己
  38. mp[u][a[u]]++;
  39. ans = (ans+a[u])%mod;
  40. for(auto &v:G[u]){
  41. if(v == fa) continue;
  42. dfs(v, u);
  43. }
  44. }
  45. int main(){
  46. ios::sync_with_stdio(false);
  47. cin>>n;
  48. for(int i=1; i<=n; i++) cin>>a[i];
  49. int u, v;
  50. for(int i=1; i<n; i++){
  51. cin>>u>>v;
  52. G[u].push_back(v), G[v].push_back(u);
  53. }
  54. dfs(1, 1);
  55. cout<<ans<<endl;
  56. return 0;
  57. }

codeforces 1230 div2的更多相关文章

  1. Codeforces #180 div2 C Parity Game

    // Codeforces #180 div2 C Parity Game // // 这个问题的意思被摄物体没有解释 // // 这个主题是如此的狠一点(对我来说,),不多说了这 // // 解决问 ...

  2. Codeforces #541 (Div2) - E. String Multiplication(动态规划)

    Problem   Codeforces #541 (Div2) - E. String Multiplication Time Limit: 2000 mSec Problem Descriptio ...

  3. Codeforces #541 (Div2) - F. Asya And Kittens(并查集+链表)

    Problem   Codeforces #541 (Div2) - F. Asya And Kittens Time Limit: 2000 mSec Problem Description Inp ...

  4. Codeforces #541 (Div2) - D. Gourmet choice(拓扑排序+并查集)

    Problem   Codeforces #541 (Div2) - D. Gourmet choice Time Limit: 2000 mSec Problem Description Input ...

  5. Codeforces #548 (Div2) - D.Steps to One(概率dp+数论)

    Problem   Codeforces #548 (Div2) - D.Steps to One Time Limit: 2000 mSec Problem Description Input Th ...

  6. 【Codeforces #312 div2 A】Lala Land and Apple Trees

    # [Codeforces #312 div2 A]Lala Land and Apple Trees 首先,此题的大意是在一条坐标轴上,有\(n\)个点,每个点的权值为\(a_{i}\),第一次从原 ...

  7. Codeforces #263 div2 解题报告

    比赛链接:http://codeforces.com/contest/462 这次比赛的时候,刚刚注冊的时候非常想好好的做一下,可是网上喝了个小酒之后.也就迷迷糊糊地看了题目,做了几题.一觉醒来发现r ...

  8. codeforces #round363 div2.C-Vacations (DP)

    题目链接:http://codeforces.com/contest/699/problem/C dp[i][j]表示第i天做事情j所得到最小的假期,j=0,1,2. #include<bits ...

  9. codeforces round367 div2.C (DP)

    题目链接:http://codeforces.com/contest/706/problem/C #include<bits/stdc++.h> using namespace std; ...

随机推荐

  1. pug的安装与使用

    说明 Pug原名不叫Pug,是大名鼎鼎的jade,后来由于商标的原因,改为Pug,哈巴狗.其实只是换个名字,语法都与jade一样.丑话说在前面,Pug有它本身的缺点--可移植性差,调试困难,性能并不出 ...

  2. python mooc 3维可视化<第一周第一单元>

    基本含义 数据->图像 分类 重点关注空间数据的可视化 方法 二维标量数据场 三维标量数据场 二位标量数据场 颜色映射法 等值线法 立体图法 层次分割法 三维标量数据场 面绘制法 体绘制法 展示 ...

  3. qt,pro文件中用于平台区分的写法

    qt,pro文件中用于平台区分的写法 切记: 大括号和平台需要在同一行中,否则会失效 unix { TARGET = appname } macx { TARGET = appname2 } win3 ...

  4. Directx11教程(63) tessellation学习(5)

    原文:Directx11教程(63) tessellation学习(5)        TS中生成细分后顶点的u,v,{w}坐标,我们根据控制点和u,w,{w}坐标生成新的顶点位置,在前面四边形的细分 ...

  5. Directx11 教程(1) 基本的windows应用程序框架(1)

    原文:Directx11 教程(1) 基本的windows应用程序框架(1)        在vs2010中,建立一个新的win32工程,名字是: myTutorialD3D11, 注意:同时勾选Cr ...

  6. Unrecognised tag: 'build'

    [ERROR] [ERROR] Some problems were encountered while processing the POMs:[ERROR] Malformed POM H:\ec ...

  7. Python对于封装性的看法

  8. InteractiveHtmlBom 在手机上无法显示 BOM List 和装配图的问题

    InteractiveHtmlBom 在手机上无法显示 BOM List 和装配图的问题 InteractiveHtmlBom 插件是一款用于 KiCad BOM 装配图生成插件. 最近新生成的 文件 ...

  9. 使用 Linux Centos Docker 安装 2Bizbix

    在 Docker 安装 2Bizbix 安装 Centos 7 安装 mysql5.5 镜像 映射好数据库的配置文件和数据库目录 在 Windows 安装 2Bizbox 安装 jboss/base- ...

  10. [转]The Curse of Dimensionality(维数灾难)

    原文章地址:维度灾难 - 柳枫的文章 - 知乎 https://zhuanlan.zhihu.com/p/27488363 对于大多数数据,在一维空间或者说是低维空间都是很难完全分割的,但是在高纬空间 ...