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 ...
随机推荐
- poj 1125 Stockbroker Grapevine(最短路 简单 floyd)
题目:http://poj.org/problem?id=1125 题意:给出一个社交网络,每个人有几个别人可以传播谣言,传播谣言需要时间.问要使得谣言传播的最快,应该从那个人开始传播谣言以及使得所有 ...
- struts2启动报错com/opensymphony/xwork2/spring/SpringObjectFactory.java:220:-1
好久没有搞struts2,今天配置strut2.2.1,启动时遇到个小问题.记录下. tomcat启动报错: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 ...
- 如何将DataTable转换成List<T>呢?
昨日在工作中,遇到一个问题:需要将查询出来的DataTable数据源,转换成List<T>的泛型集合(已知T类型).第一反应,我想肯定要用到“泛型”(这不是废话吗?都说了要转换成List& ...
- 使用MySQL
安装MySQL驱动 使用vpn $ pip install mysql-connector-python --allow-external mysql-connector-python import ...
- C语言数组和指针的理解_在取地址运算上的操作_指针加减操作_a 和&a 的区别
1.一个实例+理论分析 在了解数组和指针的访问方式前提下,下面再看这个例子: main() { int a[5]={1,2,3,4,5}; int *ptr=(int *)(&a+1); pr ...
- 移植mysql到嵌入式ARM平台
移植MySQL到嵌入式ARM平台 MySQL没有专门针对ARM的版本,移植到ARM没有官方文档可参考,因此,暂时参考这样一篇文档: http://blog.chinaunix.net/space.p ...
- CSS预处理器Sass(Scss)、Less、Stylus
CSS 预处理编译器能让我成程序化其的方式编写CSS代码,可以引入CSS中没有的变量.条件.函数等特性,从而让代码更简单易维护,但一般按预处理器语法编写的代码无法直接在浏览器中运行,需用通过工具比如g ...
- sharepoint 2010 页面添加footer方法 custom footer for sharepoint 2010 master page
转:http://blog.csdn.net/chenxinxian/article/details/8720893 在sharepoint 2010的页面中,我们发现,没有页尾,如果我们需要给页面添 ...
- ODAC访问oracle时,提示:由于以前的函数求值超时,函数求值被禁用,必须继续执行才能正常返回
这是因为调试时会自动对Local/Watch等窗口里面(或鼠标停留所在)的变量求值,为了防止用户写的程序错误(比如死循环),系统有一个超时限制,如果某个属性的get中做了很复杂的操作(而不是简单地返回 ...
- 并发编程之--ConcurrentSkipListMap
概要 本章对Java.util.concurrent包中的ConcurrentSkipListMap类进行详细的介绍.内容包括:ConcurrentSkipListMap介绍ConcurrentSki ...