首页 > 学院 > 开发设计 > 正文

[HAOI2012]容易题题解

2019-11-06 08:00:19
字体:
来源:转载
供稿:网友

https://www.luogu.org/PRoblem/show?pid=2220

题解

每次要去掉一个数位的一种选择,最后求值。 这相当于一个多项式乘法,之后,每一个要求就把要求的数位减去相应的值,但注意不要减重。所以我们要进行排序一下!! 但是还是TLE所以k<= 100000,而m<=1000000000,就是说k个要求满足word">long long re = 1; while(y){ if(y & 1)re = (re * x) % mo; x = (x * x) % mo; y >>= 1; } return re;}int main(){ long long n,m,k; scanf("%lld%lld%lld",&n,&m,&k); long long sum = (((1 + n) * n)/2) % mo; for(int i = 1;i <= k;i++) scanf("%lld%lld",&info[i].x,&info[i].y); sort(info + 1,info + 1 + k,cmp); for(int i = 1;i <= k;i++){ if(info[i].x == info[i - 1].x && info[i].y == info[i - 1].y)continue; if(info[i].x != info[i - 1].x)tot++; a[tot] += info[i].y; } 最后,以我血的教训告诉大家:取模后的减法要加模数!!

代码

#include <cstdio>#include <cstring>#include <algorithm>using namespace std;#define mo 1000000007struct node{ long long x,y;}info[100100];long long a[100100],tot;long long ans1 = 1;bool cmp(node a,node b){ if(a.x != b.x) return a.x < b.x; else return a.y < b.y;}long long quick_pow(long long x,long long y){ for(int i = 1;i <= tot;i++) ans1 = (ans1 * (sum - a[i] + mo)) % mo; long long ans2 = quick_pow(sum,m - tot); long long ans = (ans1 * ans2) % mo; printf("%lld/n",ans); return 0;}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表