codeforces 1230 div2
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的更多相关文章
- Codeforces #180 div2 C Parity Game
// Codeforces #180 div2 C Parity Game // // 这个问题的意思被摄物体没有解释 // // 这个主题是如此的狠一点(对我来说,),不多说了这 // // 解决问 ...
- Codeforces #541 (Div2) - E. String Multiplication(动态规划)
Problem Codeforces #541 (Div2) - E. String Multiplication Time Limit: 2000 mSec Problem Descriptio ...
- Codeforces #541 (Div2) - F. Asya And Kittens(并查集+链表)
Problem Codeforces #541 (Div2) - F. Asya And Kittens Time Limit: 2000 mSec Problem Description Inp ...
- Codeforces #541 (Div2) - D. Gourmet choice(拓扑排序+并查集)
Problem Codeforces #541 (Div2) - D. Gourmet choice Time Limit: 2000 mSec Problem Description Input ...
- Codeforces #548 (Div2) - D.Steps to One(概率dp+数论)
Problem Codeforces #548 (Div2) - D.Steps to One Time Limit: 2000 mSec Problem Description Input Th ...
- 【Codeforces #312 div2 A】Lala Land and Apple Trees
# [Codeforces #312 div2 A]Lala Land and Apple Trees 首先,此题的大意是在一条坐标轴上,有\(n\)个点,每个点的权值为\(a_{i}\),第一次从原 ...
- Codeforces #263 div2 解题报告
比赛链接:http://codeforces.com/contest/462 这次比赛的时候,刚刚注冊的时候非常想好好的做一下,可是网上喝了个小酒之后.也就迷迷糊糊地看了题目,做了几题.一觉醒来发现r ...
- codeforces #round363 div2.C-Vacations (DP)
题目链接:http://codeforces.com/contest/699/problem/C dp[i][j]表示第i天做事情j所得到最小的假期,j=0,1,2. #include<bits ...
- codeforces round367 div2.C (DP)
题目链接:http://codeforces.com/contest/706/problem/C #include<bits/stdc++.h> using namespace std; ...
随机推荐
- pug的安装与使用
说明 Pug原名不叫Pug,是大名鼎鼎的jade,后来由于商标的原因,改为Pug,哈巴狗.其实只是换个名字,语法都与jade一样.丑话说在前面,Pug有它本身的缺点--可移植性差,调试困难,性能并不出 ...
- python mooc 3维可视化<第一周第一单元>
基本含义 数据->图像 分类 重点关注空间数据的可视化 方法 二维标量数据场 三维标量数据场 二位标量数据场 颜色映射法 等值线法 立体图法 层次分割法 三维标量数据场 面绘制法 体绘制法 展示 ...
- qt,pro文件中用于平台区分的写法
qt,pro文件中用于平台区分的写法 切记: 大括号和平台需要在同一行中,否则会失效 unix { TARGET = appname } macx { TARGET = appname2 } win3 ...
- Directx11教程(63) tessellation学习(5)
原文:Directx11教程(63) tessellation学习(5) TS中生成细分后顶点的u,v,{w}坐标,我们根据控制点和u,w,{w}坐标生成新的顶点位置,在前面四边形的细分 ...
- Directx11 教程(1) 基本的windows应用程序框架(1)
原文:Directx11 教程(1) 基本的windows应用程序框架(1) 在vs2010中,建立一个新的win32工程,名字是: myTutorialD3D11, 注意:同时勾选Cr ...
- Unrecognised tag: 'build'
[ERROR] [ERROR] Some problems were encountered while processing the POMs:[ERROR] Malformed POM H:\ec ...
- Python对于封装性的看法
- InteractiveHtmlBom 在手机上无法显示 BOM List 和装配图的问题
InteractiveHtmlBom 在手机上无法显示 BOM List 和装配图的问题 InteractiveHtmlBom 插件是一款用于 KiCad BOM 装配图生成插件. 最近新生成的 文件 ...
- 使用 Linux Centos Docker 安装 2Bizbix
在 Docker 安装 2Bizbix 安装 Centos 7 安装 mysql5.5 镜像 映射好数据库的配置文件和数据库目录 在 Windows 安装 2Bizbox 安装 jboss/base- ...
- [转]The Curse of Dimensionality(维数灾难)
原文章地址:维度灾难 - 柳枫的文章 - 知乎 https://zhuanlan.zhihu.com/p/27488363 对于大多数数据,在一维空间或者说是低维空间都是很难完全分割的,但是在高纬空间 ...