codeforces 186C Plant
2016-09-07 00:27
369 查看
题意:每次把一个相反的(正倒相反)的三角形放到每个三角形中切割原来的图形,问n次切割后有多少个小三角形?
公式题,忘记特判0的情况wa了很多次!!!
以后一定要注意边界情况
#include <iostream>
#include <cmath>
#include <cstring>
#include <string>
#include <cstdio>
#include <algorithm>
#define rep(i, j, k) for(int i = j; i <= k; i++)
#define eps 1e-3
#define mod 1000000007
#define ll long long
using namespace std;
ll n, a, b;
ll pow (ll x, ll y)
{
if (y == 0)
return 1LL;
ll ret = pow (x, y / (1LL * 2)) % mod;
ret = (ret * ret) % mod;
if (y % (2 * 1ll))
ret = (ret * x) % mod;
return ret % mod;
}
int main ()
{
cin >> n;
if (n == 0)
{
printf ("1\n");
return 0;
}
ll base = 2 * 1LL;
ll b1 = n - 1LL;
ll b2 = n * (2 * 1LL) - 1LL;
//a = pow (2 * 1LL, n * 1LL- 1LL);
a = pow (base, b1);
b = pow (base, b2);
//b = pow (2 * 1LL, n * 1LL * 2 - 1LL);
cout << (a + b) % mod << endl;
return 0;
}
公式题,忘记特判0的情况wa了很多次!!!
以后一定要注意边界情况
#include <iostream>
#include <cmath>
#include <cstring>
#include <string>
#include <cstdio>
#include <algorithm>
#define rep(i, j, k) for(int i = j; i <= k; i++)
#define eps 1e-3
#define mod 1000000007
#define ll long long
using namespace std;
ll n, a, b;
ll pow (ll x, ll y)
{
if (y == 0)
return 1LL;
ll ret = pow (x, y / (1LL * 2)) % mod;
ret = (ret * ret) % mod;
if (y % (2 * 1ll))
ret = (ret * x) % mod;
return ret % mod;
}
int main ()
{
cin >> n;
if (n == 0)
{
printf ("1\n");
return 0;
}
ll base = 2 * 1LL;
ll b1 = n - 1LL;
ll b2 = n * (2 * 1LL) - 1LL;
//a = pow (2 * 1LL, n * 1LL- 1LL);
a = pow (base, b1);
b = pow (base, b2);
//b = pow (2 * 1LL, n * 1LL * 2 - 1LL);
cout << (a + b) % mod << endl;
return 0;
}
相关文章推荐
- CodeForces - 185A ( Plant)
- [最小割] Codeforces 434D. Nanami's Power Plant
- codeforces 185A Plant(矩阵快速幂)
- codeforces 185A Plant
- CodeForces - 185A Plant
- CodeForces - 185A Plant 矩阵快速幂
- Plant CodeForces - 185A
- CodeForces 185A - Plant
- Codeforces 185A Plant 普通快速幂取模
- CodeForces 185A Plant(公式推导+快速幂)
- Codeforces 185A Plant
- CodeForces - 185A Plant
- codeforces - 185 - A - Plant 【经典矩阵快速幂】
- codeforces 185A Plant(矩阵快速幂)
- Codeforces186C
- codeforces 101 B. Buses
- Codeforces 617C(Watering Flowers)
- CodeForces 373C Counting Kangaroos is Fun(袋鼠藏口袋,二分)
- codeforces 763A Timofey and a tree(DFS)
- codeforces 686D(树的重心)