Codeforces Round #324 (Div. 2) B. Kolya and Tanya 快速幂
B. Kolya and Tanya
Time Limit: 1 Sec
Memory Limit: 256 MB
题目连接
http://codeforces.com/contest/584/problem/B
Description
Kolya loves putting gnomes at the circle table and giving them coins, and Tanya loves studying triplets of gnomes, sitting in the vertexes of an equilateral triangle.
More formally, there are 3n gnomes sitting in a circle. Each gnome can have from 1 to 3 coins. Let's number the places in the order they occur in the circle by numbers from 0 to 3n - 1, let the gnome sitting on the i-th place have ai coins. If there is an integer i (0 ≤ i < n) such that ai + ai + n + ai + 2n ≠ 6, then Tanya is satisfied.
Count the number of ways to choose ai so that Tanya is satisfied. As there can be many ways of distributing coins, print the remainder of this number modulo 109 + 7. Two ways, a and b, are considered distinct if there is index i (0 ≤ i < 3n), such that ai ≠ bi (that is, some gnome got different number of coins in these two ways).
Input
Output
Print a single number — the remainder of the number of variants of distributing coins that satisfy Tanya modulo 109 + 7.
Sample Input
Sample Output
HINT
题意
给你一个环,环上有3n个点,每个点的权值可以是1-3,然后问你满足a[i]+a[i+1]+a[i+2]!=6的方案有多少种
题解:
反面,a[i]+a[i+1]+a[i+2]=6的情况这三个数的取值一共有7种
那么答案就是 3^(3n) - 7^n就好了
代码:
#include<stdio.h>
#include<iostream>
#include<math.h> using namespace std; #define mod 1000000007
long long quickpow(long long m,long long n,long long k)
{
long long b = ;
while (n > )
{
if (n & )
b = (b*m)%k;
n = n >> ;
m = (m*m)%k;
}
return b;
} int main()
{
long long n;
cin>>n;
cout<<(quickpow(,*n,mod) - quickpow(,n,mod) + mod) % mod <<endl;
}
Codeforces Round #324 (Div. 2) B. Kolya and Tanya 快速幂的更多相关文章
- Codeforces Round #518 (Div. 1) Computer Game 倍增+矩阵快速幂
接近于死亡的选手没有水平更博客,所以现在每五个月更一篇. 这道题呢,首先如果已经有权限升级了,那么后面肯定全部选的是 \(p_ib_i\) 最高的. 设这个值为 \(M=\max \limits_i ...
- Codeforces Round #324 (Div. 2)解题报告
---恢复内容开始--- Codeforces Round #324 (Div. 2) Problem A 题目大意:给二个数n.t,求一个n位数能够被t整除,存在多组解时输出任意一组,不存在时输出“ ...
- Codeforces Round #324 (Div. 2) B
B. Kolya and Tanya time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- Codeforces Round #324 (Div. 2)
CF的rating设置改了..人太多了,决定开小号打,果然是明智的选择! 水 A - Olesya and Rodion #include <bits/stdc++.h> using na ...
- Codeforces Round #324 (Div. 2) Kolya and Tanya 组合数学
原题链接:http://codeforces.com/contest/584/problem/B 题意: 有3*n个人围成一个圈,每个人可以分配1到3个硬币,但是相邻为n的三个人的和不能是6,问你有多 ...
- Codeforces Round #324 (Div. 2) C (二分)
题目链接:http://codeforces.com/contest/734/problem/C 题意: 玩一个游戏,一开始升一级需要t秒时间,现在有a, b两种魔法,两种魔法分别有m1, m2种效果 ...
- Codeforces Round #324 (Div. 2) E. Anton and Ira 贪心
E. Anton and Ira Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/584/probl ...
- Codeforces Round #324 (Div. 2) D. Dima and Lisa 哥德巴赫猜想
D. Dima and Lisa Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/584/probl ...
- Codeforces Round #324 (Div. 2) C. Marina and Vasya 贪心
C. Marina and Vasya Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/584/pr ...
随机推荐
- SSMS错误代码大全
0 操作成功完成. 1 功能错误. 2 系统找不到指定的文件. 3 系统找不到指定的路径. 4 系统无法打开文件. 5 拒绝访问. 6 句柄无效. 7 存储控制块被损坏. 8 存储空间不足,无法处理此 ...
- ASP.NET程序中动态修改web.config中的设置项目(后台CS代码)
using System;using System.Collections;using System.ComponentModel;using System.Data;using System.Dra ...
- Java [leetcode 12] Integer to Roman
题目描述: Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range fr ...
- Android 隐藏RadoiButton左边按钮
声明方式 添加属性 android:button=“@null”? 代码方式 radioBtn.setButtonDrawable(new StateListDrawable());
- iOS--跳转到APPstore评分
本代码适用于iOS7之后的版本: NSString *str = [NSString stringWithFormat:@"itms-apps://itunes.apple.com/app/ ...
- Oracle函数面试题
1.对字符串操作的函数? 答:ASCII() –函数返回字符表达式最左端字符的ASCII 码值 CHR() –函数用于将ASCII 码转换为字符 –如果没有输入0 ~ 255 之间的ASCII 码值C ...
- 【转】ubuntu自动挂载硬盘方法
首先建立挂载目录例如:sudo mkdir /movie #根目录下建立movie文件夹sudo mkdir /work #根目录下建立work文件夹 然后查看硬盘信息sudo fdisk -l ...
- ExpectationMaximum
2- You may have question marks in your head, especially regarding where the probabilities in the Exp ...
- HDU 4825-Xor Sum(trie)
题意: 给你一组数,开始询问给一个数 求组中与该数异或值最大的数. 分析:根据异或的特点 要想得到的异或值最大 尽可能的让两个数的每位都相反 先把给定的一组数建树,数的最后一位对应的节点保存这个数的 ...
- (二)GameMaker:Studio ——使用等高图生成3D地形
上一篇,我们讲解了GM中导入模型的方法,这节我们来讲地形. 源文件地址:http://pan.baidu.com/share/link?shareid=685772423&uk=2466343 ...