CF 584B Kolya and Tanya
题目大意:3n个人围着一张桌子,给每个人发钱,可以使1块、2块、3块,第i个人的金额为Ai。若存在第个人使得Ai + Ai+n + Ai+2n != 6,则该分配方案满足条件,求所有的满足条件的方案数 结果 MOD 1000000007。
解题思路:当 n = 1 时有总共有27中情况,其中20中满足条件,则 (27^n - 7^n)为所求结果。
代码
#include<iostream>
#include<cstdio>
#include<cstdlib>
using namespace std;
#define ll long long
#define mod 1000000007
ll pow(int a,int b){
ll ans=1,base;
base = a;
while(b){
if(b&1){
ans *= base;
ans %= mod;
}
base *= base;
base %= mod;
b >>= 1;
}
return ans;
}
int main(){
int n,t;
ll ans1,ans2;
while(scanf("%d",&n) == 1){
if(n == 1){
printf("20\n");
continue;
}
ans1 = pow(27,n);
ans2 = pow(7,n);
printf("%I64d\n",(ans1-ans2+mod)%mod);
}
return 0;
}
CF 584B Kolya and Tanya的更多相关文章
- 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/pro ...
- CF B. Kolya and Tandem Repeat
Kolya got string s for his birthday, the string consists of small English letters. He immediately ad ...
- codeforces584B Kolya and Tanya
题目链接:http://codeforces.com/problemset/problem/584/B 解题思路:当n=1时,_______ _______ ______ 三个数每位上可以 ...
- 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)
CF的rating设置改了..人太多了,决定开小号打,果然是明智的选择! 水 A - Olesya and Rodion #include <bits/stdc++.h> using na ...
- Codeforces Round #324 (Div. 2)解题报告
---恢复内容开始--- Codeforces Round #324 (Div. 2) Problem A 题目大意:给二个数n.t,求一个n位数能够被t整除,存在多组解时输出任意一组,不存在时输出“ ...
- Codeforces 584 - A/B/C/D/E - (Done)
链接:https://codeforces.com/contest/584 A - Olesya and Rodion - [水] 题解:注意到 $t$ 的范围是 $[2,10]$,对于位数小于 $2 ...
- 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 ...
- CF Tanya and Postcard
Tanya and Postcard time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
随机推荐
- libeXosip2(3-1) -- eXosip2 INVITE and Call Management
eXosip2 INVITE and Call Management SIP messages and call control API Functions int eXosip_call_set_ ...
- Asp.Net 构架(Http Handler 介绍) - Part.2
原文地址:http://www.cnblogs.com/JimmyZhang/archive/2007/09/15/894124.html 引言 在 Part.1 Http请求处理流程 一文中,我们了 ...
- Codeforce 219 div1
B 4D"部分和"问题,相当于2D部分和的拓展,我是分解成2D部分和做的: f[x1][y1][x2][y2]=true/false 表示 左上(x1,y1) 右下(x2,y2)的 ...
- python3 urllib.request.urlopen() 地址打开错误
错误内容:UnicodeEncodeError: 'ascii' codec can't encode characters in position 28-29: ordinal not in ran ...
- CF Zepto Code Rush 2014 B. Om Nom and Spiders
Om Nom and Spiders time limit per test 3 seconds memory limit per test 256 megabytes input standard ...
- Dev GridControl,GridView 显示多行文本及合并相同单元格
显示多行文本的方法 首先把gridcontrol的views的Optionsview里的RowAutoHeight设置为True 在In-place Editor Repository 里添加 Mem ...
- (转)[老老实实学WCF] 第二篇 配置WCF
第二篇 配置WCF 在上一篇中,我们在一个控制台应用程序中编写了一个简单的WCF服务并承载了它.先回顾一下服务端的代码: using System; using System.Collections. ...
- java基础2
//第一个程序 用super访问父类中被隐藏的成员变量和被重写的方法 package foxe; class superClass{ int x; superClass(){ x=4; System. ...
- 数据库分库分表(sharding)系列(二) 全局主键生成策略
本文将主要介绍一些常见的全局主键生成策略,然后重点介绍flickr使用的一种非常优秀的全局主键生成方案.关于分库分表(sharding)的拆分策略和实施细则,请参考该系列的前一篇文章:数据库分库分表( ...
- web worker使用
使用postMessage()方法传递信息.来自Worker的数据保存在event.data中.通过message和error事件与页面通信. <script> var data = [4 ...