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; ...
随机推荐
- Windows Phpstrom svn 配置
网上百度找到的解决方案行不通,就是下图两项都不选中.临时是可以的,但是到了第二天,又不行了. 以下是自己瞎弄的,居然可以了. 第一步:安装TortoiseSVN 1.8.* ,注意安装选项要选上com ...
- python 单元测试之初次尝试
python 语言中有很多单元测试框架和工具,而unittest单元测试框架作为标准python语言中的一个模块.是其他框架和工具的基础.想要进行单元测试,我们需要使用到unittest框架中的功能. ...
- Android——系统权限
Android是一个特权分隔的操作系统,每一个应用程序运行在不同的系统身份中(Linux的user ID和group ID).系统部分和不同的身份被隔离开来.因此,Linux隔离了应用程序(与其它程序 ...
- JSP Web第五章整理复习 JSP访问数据库
P164 例5-1 常用SQL语句 P178 数据库连接池 (1)连接池的作用 存储多个数据库连接对象,当程序需要时,从池中获取1个连接,程序执行完成后再还给连接池.避免数据库连接建立.关闭的开 ...
- 自定义注解--Annotation
Annotation 概念:注解 原理 是一种接口,通过反射机制中的相关API来访问annotation信息 常见的标准Annotation @Override 方法重写 @Deprecated ...
- 【python小随笔】List列表的常见函数与切片
eval()的使用 n = ["2.3","2.56"] m = [] for i in n: k = eval(i) #只是去了最外层的双引号,单引号, 规定 ...
- poj2449第K短路问题(A*算法)
启发函数:f(x)=g(x)+h(x); g(x)表示初始点到x状态的代价,h(x)表示从x的状态到目标状态的代价的估计值(并不是真实的),实际最小代价<=h(x); 起点s,终点t,x.v=s ...
- 如何在Liferay 7中创建一个简单的JSF Portlet
这个将在Liferay IDE 3.1 M3的发布版中提供创建的选项,但是你也可以通过命令行来创建. 1.这是Liferay JSF团队的官网:http://liferayfaces.org/ 你能在 ...
- 只想着一直调用一直爽, 那API凭证泄漏风险如何破?
如今各家云厂商都通过给用户提供API调用的方式来实现一些自动化编排方面的需求.为了解决调用API过程中的通信加密和身份认证问题,大多数云厂商会使用同一套技术方案—基于非对称密钥算法的鉴权密钥对,这里的 ...
- gpu命令cuda命令
# device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")os.envi ...