Codeforces Round #360 (Div. 2) C D E
每次AB秒出 到了C难度陡然上升...翻译都弄不懂...
C 给出一张图 找出两个点的覆盖集(覆盖集是指这图中每条边都有至少一个点在这个点集里面) 并且两个点集没有交集 英文很难看懂...就是二分图的判定 看看这张图是不是二分图 输出两边的点 不是二分图输出-1
坑点是这是special judge 但是题目没说 每个联通块都要进行一次bfs 那些独立点可以不输出也可以随意分配
D 给出k与n个数ci 我们知道一个未知的数x%ci的数 问能不能求出x%k的数
可以利用中国剩余定理来解
如果我们知道 x=A mod c1 = B mod c2 可以求出x的通解 x= lcm(c1,c2)q+z 这里的q是一个倍数
那么当lcm(c1,c2...)是k的倍数的时候 满足 所有的 kq都有lcm()q来对应 所以这时候一定可以通过z求出x%k
所以只需要求一下ci之间的lcm就好啦 最后看lcm是不是k的倍数
但是 直接求lcm会超int什么的
可以每次都让lcm%=k 一旦lcm为k的倍数的时候就永远为0下去了
E A有n个硬币 B有k价值的东西 A从这些硬币中找出一些使和等于k和B交换 A想知道B能利用这些硬币摆出多少的状态 都输出
设置dp[i][j] i表示A拿出的硬币的总和 j表示从这些硬币中拿出来的部分的总和 1 为存在 0 为不存在
初始dp[0][0]=1
关于代码内dp方程的转移:首先枚举硬币的种类 再枚举i 需要注意的是i要从大往小去枚举 这和背包中01和完全的区别类似 当我们从上向下枚举的时候 就不会出现同一种东西加成在小东西上 又在小东西升级的大东西上再次作用这种状况了 问题中硬币是只有一个的 所以是01 从上向下枚举 而当面对完全背包的情况下 我们可以无限制的加入东西 所以应该从小往下枚举 枚举j的时候只需要从0向k枚举就好 因为之后还会进行判断 dp[i][j]==1 这时候就说明这种状态是存在的 然后我们对dp[i+c][j]和dp[i+c][j+c]进行操作 可以看出 由于枚举硬币的顺序 每个状态的i和j都只能被放进去一种硬币
初始化的时候只做dp[0][0]就好 其余的让它自己去推...
C
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<map>
#include<math.h>
#include<iostream>
#include<queue>
using namespace std;
int n,m;
int point[100050];
struct node
{
int v;
int nex;
};
node b[200050];
int cnt;
void add(int u,int v)
{
b[cnt].v=v;
b[cnt].nex=point[u];
point[u]=cnt;
cnt++;
}
int co[100050];
bool bfs(int z)
{
queue<int >q;
q.push(z);
co[z]=1;
while(!q.empty())
{
int f=q.front();
q.pop();
for(int tt=point[f]; tt!=-1; tt=b[tt].nex)
{
int v=b[tt].v;
if(co[v]==0)
{
if(co[f]==1)
{
co[v]=2;
q.push(v);
}
else
{
co[v]=1;
q.push(v);
}
}
else if(co[v]==co[f])
{
return false;
}
else
{
continue;
}
}
}
return true;
} int main()
{
cin>>n>>m;
cnt=0;
for(int i=1; i<=n; i++)
{
point[i]=-1;
co[i]=0;
}
for(int i=1; i<=m; i++)
{
int u,v;
cin>>u>>v;
add(u,v);
add(v,u);
}
bool ans=true;
for(int i=1;i<=n;i++){
if(co[i]==0){
ans=bfs(i);
if(ans==false){
printf("-1\n");
break;
}
}
}
if(ans==true){
int res=0;
for(int i=1; i<=n; i++)
{
if(co[i]==1)
{
res++;
}
}
printf("%d\n",res);
int c=0;
for(int i=1; i<=n; i++)
{
if(co[i]==1)
{
printf("%d",i);
c++;
if(c==res)
printf("\n");
else printf(" ");
}
}
c=0;
res=0;
for(int i=1; i<=n; i++)
{
if(co[i]!=1)
{
res++;
}
}
printf("%d\n",res);
for(int i=1; i<=n; i++)
{
if(co[i]!=1)
{
printf("%d",i);
c++;
if(c==res)
printf("\n");
else printf(" ");
}
}
}
}
D
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<map>
#include<iostream>
using namespace std;
long long k;
int n;
long long gcd(long long a,long long b)
{
if(b==0)
return a;
return gcd(b,a%b);
}
long long lcm(long long a, long long b)
{
return a*b/gcd(a,b);
}
int main()
{
scanf("%d%lld",&n,&k);
long long cc;
scanf("%lld",&cc);
long long gbs=cc;
bool ans=false;
if(k==1)
{
ans=true;
}
if(n==1)
{
if(cc%k==0)
ans=true;
}
for(int i=2; i<=n; i++)
{
scanf("%lld",&cc);
if(ans==true)
continue;
gbs=lcm(cc,gbs);
gbs%=k;
if(gbs==0)
{
ans=true;
}
}
if(ans==true)
{
printf("Yes\n");
}
else printf("No\n");
}
E
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<map>
using namespace std;
int n,k;
int c[505];
int dp[500][500];
int main()
{
scanf("%d%d",&n,&k);
for(int i=1; i<=n; i++)
scanf("%d",&c[i]);
memset(dp,0,sizeof(dp));
/*for(int i=1; i<=n; i++)
{
dp[c[i]][c[i]]=dp[c[i]][0]=1;
}*/
dp[0][0]=1;
for(int i=1; i<=n; i++)
{
for(int j=k-c[i]; j>=0; j--)
{
for(int o=0; o<=k; o++)
{
if(dp[j][o]==1)
{
dp[j+c[i]][o]=1;
if(o+c[i]<=k)
{
dp[j+c[i]][o+c[i]]=1;
}
}
}
}
}
int ans=0;
for(int i=0; i<=k; i++)
{
if(dp[k][i]==1)
{
ans++;
}
}
printf("%d\n",ans);
int s=0;
for(int i=0; i<=k; i++)
{
if(dp[k][i]==1)
{
{
printf("%d",i);
s++;
if(s==ans)
printf("\n");
else printf(" ");
}
}
}
}
拖了两天才补完的cf..补题的感觉真是亦可赛艇...
Codeforces Round #360 (Div. 2) C D E的更多相关文章
- Codeforces Round #360 (Div. 1) D. Dividing Kingdom II 暴力并查集
D. Dividing Kingdom II 题目连接: http://www.codeforces.com/contest/687/problem/D Description Long time a ...
- Codeforces Round #360 (Div. 2) D. Remainders Game 数学
D. Remainders Game 题目连接: http://www.codeforces.com/contest/688/problem/D Description Today Pari and ...
- Codeforces Round #360 (Div. 2) C. NP-Hard Problem 水题
C. NP-Hard Problem 题目连接: http://www.codeforces.com/contest/688/problem/C Description Recently, Pari ...
- Codeforces Round #360 (Div. 2) B. Lovely Palindromes 水题
B. Lovely Palindromes 题目连接: http://www.codeforces.com/contest/688/problem/B Description Pari has a f ...
- Codeforces Round #360 (Div. 2) A. Opponents 水题
A. Opponents 题目连接: http://www.codeforces.com/contest/688/problem/A Description Arya has n opponents ...
- Codeforces Round #360 (Div. 1)A (二分图&dfs染色)
题目链接:http://codeforces.com/problemset/problem/687/A 题意:给出一个n个点m条边的图,分别将每条边连接的两个点放到两个集合中,输出两个集合中的点,若不 ...
- Codeforces Round #360 (Div. 1) D. Dividing Kingdom II 并查集求奇偶元环
D. Dividing Kingdom II Long time ago, there was a great kingdom and it was being ruled by The Grea ...
- Codeforces Round #360 (Div. 2) E. The Values You Can Make DP
E. The Values You Can Make Pari wants to buy an expensive chocolate from Arya. She has n coins, ...
- Codeforces Round #360 (Div. 2) E. The Values You Can Make 01背包
题目链接: 题目 E. The Values You Can Make time limit per test:2 seconds memory limit per test:256 megabyte ...
随机推荐
- Fence Repair(poj 3253)
题意: 有一个农夫要把一个木板钜成几块给定长度的小木板,每次锯都要收取一定费用,这个费用就是当前锯的这个木版的长度 给定各个要求的小木板的长度,及小木板的个数n,求最小费用 提示: 以 3 5 8 5 ...
- 关于java程序打包为EXE的若干问题
这几天在一个即时通讯系统的打包上,吃尽了苦头,到现在才算解决,现在对遇到的问题进行分析总结. 1.一开始是在export "Runnable JAR file"的时候,弹出了这样的 ...
- tnsnames.ora存放路径
tnsnames.ora存放路径: D:\app\Administrator\product\11.2.0\dbhome_1\NETWORK\ADMIN
- HDU 4612 Warm up tarjan缩环+求最长链
Warm up Problem Description N planets are connected by M bidirectional channels that allow instant ...
- MATLAB学习笔记(八)——MATLAB数值积分与微分
(一)数值积分 一.数值积分的MATLAB实现方法: 1.变步长辛普生法(quad)法: (1)调用格式: [I,n]=quad('fname',a,b,tol,trace); fname是被积函数: ...
- C#学习笔记(六)——面向对象编程简介
一.面向对象编程的含义 * 是一种模块化编程方法,使代码的重用性大大的增加. * oop技术使得项目的设计阶段需要的精力大大的增加,但是一旦对某种类型的数据表达方式达成一致,这种表达方式就可以 ...
- 使用AIDL远程调用服务中的方法
AIDL:android interface define language(接口定义语言) 作用:方便远程调用其他服务中的方法 注意:安卓四大组件都要在清单文件注册 aidl创建图: AIDL的全称 ...
- Log4net源码View之Logger解析
1.简介 Logger是Log4net的三大核心载体之一,搞清楚它的意义很重大.另外两个分别是Appender和Layout.其对应关系为一个Logger对应多个Appender,一个Appender ...
- POJ 2342 (树形DP)
题目链接: http://poj.org/problem?id=2342 题目大意:直属上司和下属出席聚会.下属的上司出现了,下属就不能参加,反之下属参加.注意上司只是指直属的上司.每个人出席的人都有 ...
- Js作用域与作用域链详解
一直对Js的作用域有点迷糊,今天偶然读到Javascript权威指南,立马被吸引住了,写的真不错.我看的是第六版本,相当的厚,大概1000多页,Js博大精深,要熟悉精通需要大毅力大功夫. 一:函数作用 ...