Codeforces Round #107 (Div. 2)
D题
并查集+组合
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
#define MOD 1000000007
int o[];
int find(int x)
{
int t,r;
t = x;
while(x != o[x])
x = o[x];
while(x != t)
{
r = o[t];
o[t] = x;
t = r;
}
return x;
}
void merge(int x,int y)
{
x = find(x);
y = find(y);
if(x != y)
o[x] = y;
}
int main()
{
int i,j,n,m,k,ans = ;
scanf("%d%d%d",&n,&m,&k);
for(i = ;i <= n;i ++)
o[i] = i;
for(i = ;i <= n;i ++)
{
if(k% == )
{
if(*i < k) continue;
if(i + k/ > n) continue;
for(j = ;j < k/;j ++)
{
merge(i-j,i++j);
}
}
else
{
if(*i- < k) continue;
if(i + k/ > n) continue;
for(j = ;j < k/;j ++)
merge(i--j,i++j);
}
}
for(i = ;i <= n;i ++)
{
if(find(i) == i)
ans ++;
}
int sd = ;
for(i = ;i <= ans;i ++)
sd = ((__int64)sd*m)%MOD;
printf("%d\n",sd);
return ;
}
Codeforces Round #107 (Div. 2)的更多相关文章
- 构造 Codeforces Round #107 (Div. 2) B. Phone Numbers
题目传送门 /* 构造:结构体排个序,写的有些啰嗦,主要想用用流,少些了判断条件WA好几次:( */ #include <cstdio> #include <algorithm> ...
- Codeforces Round #107 (Div. 1) B. Quantity of Strings(推算)
http://codeforces.com/problemset/problem/150/B 题意: 给出n,m,k,n表示字符串的长度为n,m表示字符种类个数,k表示每k个数都必须是回文串,求满足要 ...
- Codeforces Round #107 (Div. 2)---A. Soft Drinking
Soft Drinking time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- Codeforces Round #271 (Div. 2)题解【ABCDEF】
Codeforces Round #271 (Div. 2) A - Keyboard 题意 给你一个字符串,问你这个字符串在键盘的位置往左边挪一位,或者往右边挪一位字符,这个字符串是什么样子 题解 ...
- Codeforces Round #272 (Div. 2) 题解
Codeforces Round #272 (Div. 2) A. Dreamoon and Stairs time limit per test 1 second memory limit per ...
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
随机推荐
- JAVA中获取当前系统时间及格式转换
JAVA中获取当前系统时间 一. 获取当前系统时间和日期并格式化输出: import java.util.Date;import java.text.SimpleDateFormat; publi ...
- Daily Build
Daily Build 是一件非常有意义的事情,也是敏捷开发中关于 “持续集成” 的一个实践.Daily Build 对于开发来说有如下好处: 保证了每次 check in 的代码可用,不会造成整个工 ...
- java8--类加载机制与反射(java疯狂讲义3复习笔记)
本章重点介绍java.lang.reflect包下的接口和类 当程序使用某个类时,如果该类还没有被加载到内存中,那么系统会通过加载,连接,初始化三个步骤来对该类进行初始化. 类的加载时指将类的clas ...
- [NHibernate]缓存(NHibernate.Caches)
系列文章 [Nhibernate]体系结构 [NHibernate]ISessionFactory配置 [NHibernate]持久化类(Persistent Classes) [NHibernate ...
- Android之layout_gravity与gravity解析
相信layout_gravity和gravity这两个属性一直困扰着很多人,很多初学者都分不清这两个属性有什么区别,以及怎样区分它们.它们中,有一个表示的是一个控件在父布局中的位置,而另一个表示的是一 ...
- util类中非静态方法中注入serivce,在controller层是使用util。
今天碰到如题的问题,刚一开始在util中注入service总是注入失败,起初我以为是util中没有注入成功,debug看了一下果然注入不进来. 然后各种纠结,最终坑爹的问题是在controller直接 ...
- shell--2.shell数组
shell 数组 (1)定义数组 shell中,用括号表示数组,数组元素用空格分开,定义数组的一般形式 arrt_name=(val1 val2 val3) 或者 arry_name=(val1 va ...
- redis部署
下载软件 [root@localhost /]# wget http://download.redis.io/releases/redis-2.8.9.tar.gz 解压.编译.安装 [root@lo ...
- js框架设计1.2对象扩展笔记
需要一个新的功能添加到我们的命名空间上.这方法在JS中被叫做extend或者mixin,若是遍历属性用一下1.1代码,则会遍历不出原型方法,所以1.2介绍的是mass Framework里的mix方法 ...
- rpm 与 yum 源
rpm rpm -e 删除软件包rpm -i 安装软件包rpm -U 更新软件包rpm -qa ...