hdu_6050: Funny Function (2017 多校第二场 1006) 【找规律】

题目链接

暴力打个表找下规律就好了,比赛时看出规律来了倒是,然而看这道题看得太晚了,而且高中的那些数列相关的技巧生疏了好多,然后推公式就比较慢。。其实还是自身菜啊。。

公式是

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;

const LL mod=1e9+7;
LL qpow(LL x,LL n)        //求x^n%mod
{
    LL ret=1;
    for(; n; n>>=1)
    {
        if(n&1) ret=ret*x%mod;
        x=x*x%mod;
    }
    return ret;
}
LL inv(LL x)
{
    return qpow(x,mod-2);
}

int T;
LL n,m;
LL ans;

int main()
{
    scanf("%d",&T);
    while(T--)
    {
        scanf("%lld%lld",&n,&m);
        if(n&1)    ans=(qpow(qpow(2,n)-1,m-1)*2%mod+1)*inv(3)%mod;
        else ans=qpow(qpow(2,n)-1,m-1)*2%mod*inv(3)%mod;
        printf("%lld\n",ans);
    }
}
时间: 2024-07-29 07:40:30

hdu_6050: Funny Function (2017 多校第二场 1006) 【找规律】的相关文章

hdu_6055 : Regular polygon (2017 多校第二场 1011) 【计算几何】

题目链接 有个结论: 平面坐标系上,坐标为整数的情况下,n个点组成正n边形时,只可能组成正方形. 然后根据这个结论来做. 我是先把所有点按照 x为第一关键字,y为第二关键字 排序,然后枚举向量 (p[i]->p[j]) (j>i),只判断这个向量左侧可否存在两个点与它一起构成一个正方形.这样算的结果是,计数每个正方形时,它的靠右和靠下的两条边都会为ans贡献一个单位,所以最后ans要除以2. #include<bits/stdc++.h> using namespace std;

hdu_6047: Maximum Sequence (2017 多校第二场 1003)【贪心】

题目链接 可以贪心写,先把b数组按从小到大的顺序排个序,根据b[i]的值来产生a[n+i] 借助一个c数组,c[i]记录,j从i到n,a[j]-j的最大值,再加上一个实时更新的变量ma,记录从n+1到当前之前的a[n+i]-(n+i)的最大值,每次把max(c[b[i]],ma)的值赋给a[n+i] #include<bits/stdc++.h> using namespace std; typedef long long LL; const int N=3e5+7; const int mo

hdu5739Fantasia(多校第二场1006) 割点+逆元

Fantasia Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Problem Description Professor Zhang has an undirected graph G with n vertices and m edges. Each vertex is attached with a weight wi. Let Gi be the graph aft

多校第二场 简单排序计算

思路:先按交叉相乘之差排序好了计算就行了. #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <map> #include <cstdlib> #include <queue> #include <stack> #include <vector> #include <ctype.

2018-3-17-湖南多校第二场

湖南多校第2场 A:太水 队友直接秒了 C: Hedwig's Ladder 队友打了个表,然后一眼规律 类似于斐波拉契 1 #include <cstdio> 2 #include <cstring> 3 #include <queue> 4 #include <cmath> 5 #include <algorithm> 6 #include <set> 7 #include <iostream> 8 #include

hdu 5305 Friends(2015多校第二场第6题)记忆化搜索

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5305 题意:给你n个人,m条关系,关系可以是online也可以是offline,让你求在保证所有人online关系的朋友和offline关系的朋友相等的情况下,这样的情况有多少种. 思路:因为online关系和offline关系的人数相等,而且m最多才28,所以只要枚举每个人的一半的关系是否符合要求即可,而且根据题意m是奇数或者有一个人的总关系为奇数那么就没有符合要求的情况,这样可以排除很多情况.

2015多校第二场 1004( Delicious Apples )

题意:有一条圆形的路,你的仓库在0点,这条路长l,然后有n个苹果树,每个数的坐标是xi(顺时针),每棵树上有ai个苹果.你有个篮子,能装k个苹果,问你用这个篮子将所有苹果装回仓库所走的最短路为多少? 1≤n,k≤105,ai≥1,a1+a2+...+an≤105 1≤L≤109 0≤x[i]≤L 请特别注意上面的苹果个数的条件.因为我的学长 就是从这个条件成功做出了这道题,orz! 因为苹果数不超过10^5,所以将每个苹果当作点. 用一个数组pos记录每个苹果距0点的距离,排序后,然后就可以用另

多校第二场 1004 hdu 5303 Delicious Apples(背包+贪心)

题目链接: 点击打开链接 题目大意: 在一个周长为L的环上.给出n棵苹果树.苹果树的位置是xi,苹果树是ai,苹果商店在0位置,人的篮子最大容量为k,问最少做多远的距离可以把苹果都运到店里 题目分析: 首先我们能够(ˇ?ˇ) 想-,假设在走半圆之内能够装满,那么一定优于绕一圈回到起点.所以我们从中点将这个圈劈开.那么对于每一个区间由于苹果数非常少,所以能够利用belong[x]数组记录每一个苹果所在的苹果树位置,然后将苹果依照所在的位置排序,那么也就是我们知道每次拿k个苹果的代价是苹果所在的最远

2015 多校赛 第二场 1006 (hdu 5305)

Problem Description There are n people and m pairs of friends. For every pair of friends, they can choose to become online friends (communicating using online applications) or offline friends (mostly using face-to-face communication). However, everyo