C

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

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

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<bitset> using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
#define pb(x) push_back(x)
#define cls(x, val) memset(x, val, sizeof(x))
#define fi first
#define se second
#define mp(x, y) make_pair(x, y)
#define inc(i, l, r) for(int i=l; i<=r; i++)
const int inf = 0x3f3f3f3f;
const int maxn = 2000+10;
int n, m;
int l[maxn], r[maxn];
bool vis[11][11];
//数组开小了,然后就会不断的覆盖。。。
int domi[8];
int ans; void check(){
int tot = 0;
cls(vis, 0); for(int i=1; i<=m; i++){
int a = domi[l[i]], b=domi[r[i]];
if(a>b) swap(a, b);
if(!vis[a][b]){
vis[a][b] = true;
tot++;
}
} if(tot>ans) ans = tot;
//cout<<"---"<<ans<<endl;
} void dfs(int dep){
if(dep>n){
check();
return ;
}
for(int i=1; i<=6; i++){
domi[dep] = i;
dfs(dep+1);
} } int main(){
ios::sync_with_stdio(false);
cin>>n>>m;
ans = 0;
for(int i=1; i<=m; i++){
cin>>l[i]>>r[i];
}
dfs(1);
cout<<ans<<endl; return 0;
}

D

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

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

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<bitset>
#include <unordered_map> using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
#define pb(x) push_back(x)
#define cls(x, val) memset(x, val, sizeof(x))
#define fi first
#define se second
#define mp(x, y) make_pair(x, y)
#define inc(i, l, r) for(int i=l; i<=r; i++)
const int inf = 0x3f3f3f3f;
const int maxn = 7000+10;
int n;
int idx;
ll a[maxn];
ll c[maxn];
ll b[maxn];
int val[maxn];
ll ans = 0;
unordered_map<ll, int> num; int main(){
ios::sync_with_stdio(false);
cin>>n;
for(int i=1; i<=n; i++){
cin>>a[i];
num[a[i]]++;
if(num[a[i]]>=2) {
c[++idx] = a[i];
}
}
for(int i=1; i<=n; i++) cin>>b[i];
for(int i=1; i<=idx; i++){
for(int j=1; j<=n; j++){
//i覆盖了j
if((c[i]&a[j]) == a[j]) val[j] = 1;
}
}
for(int i=1; i<=n; i++) ans += (val[i]*b[i]);
cout<<ans<<endl; return 0;
}

E

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

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<bitset>
#include <unordered_map> using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
#define pb(x) push_back(x)
#define cls(x, val) memset(x, val, sizeof(x))
#define fi first
#define se second
#define mp(x, y) make_pair(x, y)
#define inc(i, l, r) for(int i=l; i<=r; i++)
const int inf = 0x3f3f3f3f;
const int maxn = 2e5+10;
const int mod = 1e9+7; ll a[maxn];
vector<int> G[maxn];
int n;
unordered_map<ll, int> mp[maxn];
ll ans; void dfs(int u, int fa){
for(auto &it:mp[fa]){
//更新前面的节点到u节点的权值和。
ll temp = __gcd(it.fi, a[u]);
mp[u][temp]+=(it.se)%mod;
ans = (ans + (temp*it.se%mod))%mod;
}
//更新自己到自己
mp[u][a[u]]++;
ans = (ans+a[u])%mod; for(auto &v:G[u]){
if(v == fa) continue;
dfs(v, u);
}
} int main(){
ios::sync_with_stdio(false);
cin>>n;
for(int i=1; i<=n; i++) cin>>a[i];
int u, v;
for(int i=1; i<n; i++){
cin>>u>>v;
G[u].push_back(v), G[v].push_back(u);
}
dfs(1, 1); cout<<ans<<endl;
return 0;
}

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. CSS-DOM的小知识(二)

    上篇文章说到,通过element.style.property可以获得元素的样式,但是style属性只能够返回内嵌样式,对于外部样式表的样式和head中的style样式都无法获取,这就限制了此方法的使 ...

  2. linux安装软件报错: Can't locate ExtUtils/Embed.pm in @INC...

    安装snmp服务, 中间报错: Can't locate ExtUtils/Embed.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/l ...

  3. HTML 实体字符

    有些字符,像(<)这类的,对HTML来说是有特殊意义的,所以这些字符是不允许在文本中使用的.要在HTML中显示(<)这个字符,我们就必须使用实体字符. 实体字符 有一些字符对HTML来讲是 ...

  4. [LeetCode] Evaluate Reverse Polish Notation [2]

    题目 Evaluate the value of an arithmetic expression in Reverse Polish Notation. Valid operators are +, ...

  5. freemarker自定义标签(与java合用)

    自定义类继承FreemarkerManager类,重写protected Configuration createConfiguration(ServletContext servletContext ...

  6. LintCode_67 二叉树中序遍历

    题目 给出一棵二叉树,返回其中序遍历 C++ 非递归 vector<int> inorderTraversal(TreeNode *root) { // write your code h ...

  7. php-imagick扩展

    介绍 magick 是用 ImageMagic API 来创建和修改图像的PHP官方扩展.ImageMagick® 是用来创建,编辑,合并位图图像的一套组件. 它能够用于读取,转换,写入多种不同格式的 ...

  8. python os 模块介绍

    """ 重命名文件 os.rename(src,dst) os.rename('123.txt','124.txt') 删除文件 os.remove(path) os.r ...

  9. 安装mongoDB时,总是报错,启动不了

    安装教程地址:https://blog.csdn.net/fengtingyan/article/details/88371232 原文地址:https://blog.csdn.net/qq_2008 ...

  10. jmeter测试APP时如何录制脚本

    jmeter录制脚本需要注意的点: (1)手机和电脑需要处于一个局域网内(如手机和电脑所使用一个wifi) (2)设置手机代理的时候手机IP填写本机IP,端口号要和jmeter的相同,一般情况下端口号 ...