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. plotroc.m

    function out1 = plotroc(varargin) %PLOTROC Plot receiver operating characteristic. % % <a href=&q ...

  2. 产生冠军 HDU - 2094 (拓扑排序)

    分析: 当有且只有一个节点入度为0时,该节点即为冠军,否则不能产生冠军.所以以下代码中只要入度大于0的无论是几都将其设置为1. #include <stdio.h> #include &l ...

  3. <第一周>降维

    PCA 矩阵的主成分就是其协方差矩阵对应的特征向量,按照对应的特征值大小进行排序,最大的特征值为第一主成分,以此类推 主要过程 对所有样本进行中心化 计算样本的协方差矩阵 XX.T 对协方差矩阵做特征 ...

  4. shops

    #!/usr/bin/env python #coding:utf- import urllib2,sys,re,os,string reload(sys); sys.setdefaultencodi ...

  5. vue中element-ui添加按钮

    <div v-for="(v,i) in list"> <el-form label-width="120px" size="sma ...

  6. 目录中的pwd、cd及ls命令

    1.pwd命令(确定当前所在目录) pwd命令以绝对路径的方式显示用户当前工作目录.命令将当前目录的全路径名称(从根目录)写入标准输出.全部目录使用/分隔.第一个/表示根目录,最后一个目录是当前目录. ...

  7. 【JZOJ4934】【NOIP2017GDKOI模拟1.12】a

    helpless fucking 结论:如果一个数可以被对于a序列中每个数的最大公约数整除,那么它就是好的. Bitch Man 感性证明: 贪心地想,对于a序列中的任意两个数,它们的最大公约数可由这 ...

  8. python 模块的作用

  9. 【时光回溯】【JZOJ3568】【GDKOI2014】小纪的作业题

    题目描述 输入 输出 有M行,每个询问一行,输出结果mod 1,000,000,007的值. 样例输入 10 3 3 5 1 2 3 1 3 5 2 1 7 9 3 9 2 3 样例输出 10 19 ...

  10. JavaScript的六种数据类型与隐式转换

    一.六种数据类型 javascript的数据类型包括: (1)基本数据类型:number.string.boolean.null.undefined (2)对象:object object又包括Fun ...