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连试试水的深浅..... ...
随机推荐
- ecshop 后台时间调用
<script type="text/javascript" src="../js/calendar.php?lang={$cfg_lang}">& ...
- linux下apache各种跳转(包括伪静态)的配置
1.404跳转: vi /etc/httpd/conf/httpd.conf 在虚拟主机配置里添加一行:ErrorDocument 404 /404.html 2.301跳转: 1)将不带www的 ...
- 【转】Java enum的用法详解
用法一:常量 在JDK1.5 之前,我们定义常量都是: public static fianl.... .现在好了,有了枚举,可以把相关的常量分组到一个枚举类型里,而且枚举提供了比常量更多的方法. p ...
- 理解Kalman滤波的使用
Kalman滤波简介 Kalman滤波是一种线性滤波与预测方法,原文为:A New Approach to Linear Filtering and Prediction Problems.文章推导很 ...
- 关于ajax的提交未完再续!
$.ajax({ cache: true, type: "POST", url:"__URL__/add", data:$('#myform').seriali ...
- Eclipse快捷键与使用技巧总结
快捷键 功能 Ctrl + / 双斜杠注释 Ctrl + Shilft + / 块注释 Alt + / 代码提示 Ctrl + I (或 Ctrl + Shift + F) 格式化代码 Ctrl + ...
- CSS样式自动换行(强制换行)与强制不换行
自动换行问题,正常字符的换行是比较合理的,而连续的数字和英文字符常常将容器撑大,挺让人头疼,下面介绍的是CSS如何实现换行的方法 对于div,p等块级元素,正常文字的换行(亚洲文字和非亚洲文字)元素拥 ...
- extractor
package scrollable.excel.reader; import java.io.IOException; import java.io.InputStream; import java ...
- Linux-文件和目录操作命令
1. ls命令 显示当前目录下的内容,常见的参数有3个: -a -f -l 1 ls -a 显示隐藏文件 2 ls -F 在列出的文件后加符号 3 ls -l 长格式显示文件内容 2. cd命令 cd ...
- nginx+ISS 负载均衡 快速入门
第一:下载 http://pan.baidu.com/s/1dDwapbF 或者官网 http://nginx.org/en/download.html 启动服务: 直接运行nginx.exe,缺点控 ...