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. 2016年中国独角兽企业估值榜 TOP300

    2016年中国独角兽企业估值榜 TOP300[完整榜单] 类型:品牌资讯/名企动态 阅读:6735次 来源: 中商情报网 我要评论   摘要:独角兽公司是什么?独角兽公司指的是那些估值达到10亿美元以 ...

  2. Python多线程在爬虫中的应用

    题记:作为测试工程师经常需要解决测试数据来源的问题,解决思路无非是三种:(1)直接从生产环境拷贝真实数据 (2)从互联网上爬取数据 (3)自己用脚本或者工具造数据.前段时间,为了获取更多的测试数据,笔 ...

  3. passive的作用和原理

    passived到底有什么用? passived主要用于优化浏览器页面滚动的性能,让页面滚动更顺滑~~ passived产生的历史时间线 addEventListener():大家都是认识的,为dom ...

  4. POJ 2078

    16ms 解法: #include <cstdio> //using namespace std; ][]; ][]; ]; ]; int n,min,max; void solve(in ...

  5. JavaScript--结合CSS变形、缩放能拖拽的登录框

    上例图: 代码块: <!DOCTYPE html> <html> <head lang="en"> <meta charset=" ...

  6. Spring简介+HelloWorld

    IoC Container: 这是最重要的,也是最基础的, Spring的基础.它的作用是配置和Java对象的生命周期管理. DAO, ORM, AOP, WEB: 该模块可用于将工具或框架集成到了S ...

  7. Android LruCache源码简介

    package android.util; import java.util.LinkedHashMap; import java.util.Map; /** * A cache that holds ...

  8. jQuery打飞机游戏

    在线演示 本地下载

  9. rqnoj86 智捅马蜂窝

    题目描述 背景 为了统计小球的方案数,平平已经累坏了.于是,他摘掉了他那800度的眼镜,躺在树下休息. 后来,平平发现树上有一个特别不一样的水果,又累又饿的平平打算去把它摘下来. 题目描述 现在,将大 ...

  10. JavaScript--兼容问题总结

    以下兼容主要面向IE8以上的兼容. 一.window.navigator浏览器信息 <script> console.log(window.navigator); // 用户浏览器的类型 ...