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连试试水的深浅..... ...
随机推荐
- [nosql之redis]yum安装redis
1.首先对于这种nosql来说目前我用到的功能很少,所以感觉没有必要去优化他跟不需要去编译安装.今天来介绍下一个yum安装redis 步骤1:安装扩展yum库 [root@localhost ~]# ...
- 大熊君{{bb}}------春节期间你跳槽了吗?
时间过的很快,转眼间又快过春节了,推荐你在春节期间跳槽,是基于以下几个原因: 1,命中率高 通常情况下,所有公司都会在年底进行一定幅度的裁员,而惟独这家公司在招工,这等于明摆着告诉公众他们现在面临严重 ...
- ML 基础知识
A computer program is said to learn from experience E with respect to some task T and some performan ...
- nyoj220 推桌子(贪心算法)
这道题太坑了,from 和to有可能写反,还得正过来: 推桌子 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描述 The famous ACM (Advanced Co ...
- Shell入门教程:流程控制(7)break和continue
第一节:breank命令 4种循环 for.while.until.select,如果想要提早结束循环,可在循环中使用break命令.执行break时,会跳出一层的循环,如果想跳出多层循环,可在bre ...
- BZOJ 1131: [POI2008]Sta
Description 一棵树,问以那个节点为根时根的总和最大. Sol DFS+树形DP. 第一遍统计一下 size 和 d. 第二遍转移根,统计答案就行了. Code /************* ...
- python写计算器
#!/usr/bin/env python # -*- coding:utf-8 -*- import re def chu(arg1): #定义加减 arg = arg1[0] #beacuse p ...
- Odd Even Linked List
Given a singly linked list, group all odd nodes together followed by the even nodes. Please note her ...
- ios 抓取真机的网络包
一直被如何从真机上抓包所困扰!今天偶然看到了最简单有效的方法!分享一下: 原地址链接 http://blog.csdn.net/phunxm/article/details/38590561 通过 R ...
- (转)nginx优化 实现10万并发访问量
转自http://www.cnblogs.com/pricks/p/3837149.html 一般来说nginx配置文件中对优化比较有作用的为以下几项:worker_processes 8;1 ngi ...