重走长征路---OI每周刷题记录---12月13日 2014

总目录详见https://blog.csdn.net/mrcrack/article/details/84471041

做题原则,找不到测评地址的题不做。2018-11-28

重走长征路---OI每周刷题记录---12月13日  2014

本周共计 题+题

测评地址:

heap+贪心:

1.「bzoj2802」[Poi2012]Warehouse Store

heap+st表+点分治+贪心:

2.「bzoj3784」树上的路径

dp:

3.「bzoj3770」疯狂的限制

dfs序+线段树:

4.「bzoj3653」谈笑风生

模拟:

5.「codechefCAPPLE」Chef and Apple Trees

dfs+博弈论+树状数组:

6.「bzoj2819」Nim

高精度:

7.「bzoj2656」[Zjoi2012]数列(sequence)

快速幂:

8.「bzoj2751」[HAOI2012]容易题(easy)   //在线测评地址https://www.luogu.org/problemnew/show/P2220

dp:

9.「bzoj3174」[Tjoi2013]拯救小矮人

计算几何+最小环:

10.「bzoj1027」[JSOI2007]合金

最大流:

11.「bzoj2929」[Poi1999]洞穴攀行

fail树:

12.「bzoj3172」[Tjoi2013]单词

矩阵乘法+倍增:

13.「bzoj2165」大楼

kdtree:

14.「BZOJ2716/2648」SJY摆棋子

splay:

15.「codevs1743」反转卡片

rope:

16.「codevs1743」反转卡片

树形dp:

17.NOI2011道路修建

dfs序+树上倍增+线段树:

18.「bzoj3306」树

manacher+树状数组:

19.「bzoj3791」神奇项链

倍增+高斯消元

20.「hdu3949」XOR

link cut tree:

21.「hdu4010」Query on The Trees 

22.「hdu5002」Tree

dfs+高斯消元:

23.「bzoj2115」[Wc2011] Xor

仙人掌+dp:

24.「bzoj1487」[HNOI2009]无归岛

数位dp:

25.「hdu3555」Bomb 「数位动规练习」准考证

状压dp:

26.「bzoj1226」[SDOI2009]学校食堂Dining

tarjan+树形dp:

27.「bzoj2427」[HAOI2010]软件安装

贪心:

28.「cf494A」Treasure

kmp+dp:

29.「cf494B」Obsessive String

题解:

heap+贪心:

1.「bzoj2802」[Poi2012]Warehouse Store

heap+st表+点分治+贪心:

2.「bzoj3784」树上的路径

dp:

3.「bzoj3770」疯狂的限制

dfs序+线段树:

4.「bzoj3653」谈笑风生

模拟:

5.「codechefCAPPLE」Chef and Apple Trees

dfs+博弈论+树状数组:

6.「bzoj2819」Nim

高精度:

7.「bzoj2656」[Zjoi2012]数列(sequence)

快速幂:

8.「bzoj2751」[HAOI2012]容易题(easy)

//P2220 [HAOI2012]容易题
//在线测评地址https://www.luogu.org/problemnew/show/P2220
//输出0,应该可以骗到10分。
//想想了,考容斥原理。
//样例,数列12种计算如下
//先计算A[1]取1,A[2]取2,3,A[4]取3的数量,如下:
//1*3*3*3+2*3*3*3+1*3*3*3-1*2*3*3-1*1*3*3-2*1*3*3+1*2*1*3=69
//再计算总的数量3*3*3*3=81
//符合条件的数量81-69=12
//n=4,m=10时,4^10=1048576,深搜dfs可以得30分
//https://blog.csdn.net/yyx2000/article/details/68953780
//https://www.cnblogs.com/nietzsche-oier/p/6223515.html
//https://blog.csdn.net/acerandaker/article/details/83113757
//https://www.luogu.org/blog/user29936/solution-p2220
//上面四篇文章可以学习。
//该题难在想法,而不是算法。
//从 1000000007 看,long long是省不了了
//提交70分,测试点2,9,10WA。2019-4-16
//添加
//    if(m<cnt){
//        printf("0\n");
//        return 0;
//    }
//提交70分,测试点2,9,10WA。2019-4-16
//以下为70分代码。
//翻看他人代码,才觉察到计算过程会溢出 sum=(LL)n*(n+1)/2;//此处写成sum=n*(n+1)/2;因为n是int要溢出。
//提交70分,测试点2,9,10WA。2019-4-17
//发现int b[maxn]马上改成LL b[maxn],提交70分,测试点2,9,10WA。2019-4-17
//ans=ans*quick_pow(m-cnt,sum%mod)%mod;//此处写成ans=ans*quick_pow(m-cnt,sum)%mod;容易溢出
//提交AC,终于AC了,2019-4-17
//回顾整个过程70分算法没有问题,之后的30分,一直在int中与溢出作斗争。有三处要注意,如上修改过程,希望对后来者有帮助。
//以下为AC代码。2019-4-17
#include <cstdio>
#include <algorithm>
#define LL long long
#define mod 1000000007
#define maxn 100100
using namespace std;
int n,m,k,cnt=0;
LL sum,ans=1,b[maxn];//之前写成int b[maxn];
struct node{
    int x,y;
}a[maxn];
int cmp(node a,node b){
    if(a.x==b.x)return a.y<b.y;
    return a.x<b.x;
}
LL quick_pow(LL n,LL a){
    LL ret=1;
    while(n){
        if(n&1)ret=ret*a%mod;
        a=a*a%mod;
        n>>=1;
    }
    return ret;
}
int main(){
    int i;
    scanf("%d%d%d",&n,&m,&k);
    sum=(LL)n*(n+1)/2;//此处写成sum=n*(n+1)/2;因为n是int要溢出。
    for(i=1;i<=k;i++)scanf("%d%d",&a[i].x,&a[i].y);
    a[0].x=0,a[0].y=0;//冗余数据
    sort(a+1,a+1+k,cmp);
    for(i=1;i<=k;i++)
        if(a[i].x!=a[i-1].x)b[++cnt]=a[i].y;
        else if(a[i].y!=a[i-1].y)b[cnt]+=a[i].y;//此处写成 else b[cnt]+=a[i].y;查了会。
    if(m<cnt){
        printf("0\n");
        return 0;
    }
    for(i=1;i<=cnt;i++) ans=(sum-b[i])%mod*ans%mod;
    ans=ans*quick_pow(m-cnt,sum%mod)%mod;//此处写成ans=ans*quick_pow(m-cnt,sum)%mod;容易溢出
    printf("%lld\n",ans);
    return 0;

//P2220 [HAOI2012]容易题
//在线测评地址https://www.luogu.org/problemnew/show/P2220 
//输出0,应该可以骗到10分。 
//想想了,考容斥原理。 
//样例,数列12种计算如下 
//先计算A[1]取1,A[2]取2,3,A[4]取3的数量,如下: 
//1*3*3*3+2*3*3*3+1*3*3*3-1*2*3*3-1*1*3*3-2*1*3*3+1*2*1*3=69 
//再计算总的数量3*3*3*3=81
//符合条件的数量81-69=12
//n=4,m=10时,4^10=1048576,深搜dfs可以得30分 
//https://blog.csdn.net/yyx2000/article/details/68953780
//https://www.cnblogs.com/nietzsche-oier/p/6223515.html
//https://blog.csdn.net/acerandaker/article/details/83113757
//https://www.luogu.org/blog/user29936/solution-p2220
//上面四篇文章可以学习。
//该题难在想法,而不是算法。
//从 1000000007 看,long long是省不了了 
//提交70分,测试点2,9,10WA。2019-4-16
//添加 
//    if(m<cnt){
//        printf("0\n");
//        return 0;
//    }
//提交70分,测试点2,9,10WA。2019-4-16
//以下为70分代码。 
#include <cstdio>
#include <algorithm>
#define LL long long
#define mod 1000000007
#define maxn 100100
using namespace std;
int n,m,k,b[maxn],cnt=0;
LL sum,ans=1;
struct node{
    int x,y;
}a[maxn];
int cmp(node a,node b){
    if(a.x==b.x)return a.y<b.y;
    return a.x<b.x;
}
LL quick_pow(LL n,LL a){
    LL ret=1;
    while(n){
        if(n&1)ret=ret*a%mod;
        a=a*a%mod;
        n>>=1;
    }
    return ret;
}
int main(){
    int i;
    scanf("%d%d%d",&n,&m,&k);
    sum=n*(n+1)/2;
    for(i=1;i<=k;i++)scanf("%d%d",&a[i].x,&a[i].y);
    a[0].x=0,a[0].y=0;//冗余数据 
    sort(a+1,a+1+k,cmp);
    for(i=1;i<=k;i++)
        if(a[i].x!=a[i-1].x)b[++cnt]=a[i].y;
        else if(a[i].y!=a[i-1].y)b[cnt]+=a[i].y;//此处写成 else b[cnt]+=a[i].y;查了会。 
    if(m<cnt){
        printf("0\n");
        return 0;
    }
    for(i=1;i<=cnt;i++){
        if(sum<=b[i]){//没有合法的数列 
            printf("0\n");
            return 0;
        }
        ans=(sum-b[i])%mod*ans%mod;
    }
    ans=ans*quick_pow(m-cnt,sum)%mod;
    printf("%lld\n",ans);
    return 0;

dp:

9.「bzoj3174」[Tjoi2013]拯救小矮人

计算几何+最小环:

10.「bzoj1027」[JSOI2007]合金

最大流:

11.「bzoj2929」[Poi1999]洞穴攀行

fail树:

12.「bzoj3172」[Tjoi2013]单词

矩阵乘法+倍增:

13.「bzoj2165」大楼

kdtree:

14.「BZOJ2716/2648」SJY摆棋子

splay:

15.「codevs1743」反转卡片

rope:

16.「codevs1743」反转卡片

树形dp:

17.NOI2011道路修建

dfs序+树上倍增+线段树:

18.「bzoj3306」树

manacher+树状数组:

19.「bzoj3791」神奇项链

倍增+高斯消元

20.「hdu3949」XOR

link cut tree:

21.「hdu4010」Query on The Trees 

22.「hdu5002」Tree

dfs+高斯消元:

23.「bzoj2115」[Wc2011] Xor

仙人掌+dp:

24.「bzoj1487」[HNOI2009]无归岛

数位dp:

25.「hdu3555」Bomb 「数位动规练习」准考证

状压dp:

26.「bzoj1226」[SDOI2009]学校食堂Dining

tarjan+树形dp:

27.「bzoj2427」[HAOI2010]软件安装

贪心:

28.「cf494A」Treasure

kmp+dp:

29.「cf494B」Obsessive String

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值