Codeforces 810C Do you want a date? 题解
来源:互联网 发布:ios多线程编程 面试 编辑:程序博客网 时间:2024/06/05 12:08
题意
求一个集合的所有非空子集的最大数与最小数之差的和对109+7 取模的结果
思路
考虑每个数可以作为多少个子集最大数,多少个子集的最小数,先对集合中的数从小到大排个序,对于第i位,i从0开始,它作为最大数就是在比它小的i个数中至少取1个,取它且不取比它大的数,那么数量就是2i−1 ,它作为最小数就是在比它大的(n-1-i)个数中至少取1个,取它且不取比它小的数,那么数量就是2n−1−i−1 ,那么我们对于每个数,就加上它乘它作为最大数的集合数量减去它乘它作为最小数的集合数量,算完所有数就可以了,注意取模操作
代码
#include <cstdio>#include <algorithm>using namespace std;#define mod 1000000007long long x[300001];long long mul[300001];int main(){ long long n,ans; scanf("%I64d",&n); for(long long i=0;i<n;i++) scanf("%I64d",&x[i]); mul[0]=1; for(long long i=1;i<=n;i++) mul[i]=(mul[i-1]*2)%mod; sort(x,x+n); ans=0; for(long long i=0;i<n;i++) { ans=(ans+(x[i]*((mul[i]-1+mod)%mod))%mod)%mod; ans=(ans-(x[i]*((mul[n-1-i]-1+mod)%mod))%mod+mod)%mod; } printf("%I64d\n",ans); return 0;}
阅读全文
0 0
- Codeforces 810C Do you want a date? 题解
- Codeforces 810C Do you want a date 枚举
- CodeForces 810C Do you want a date? 【数学】【排序】
- codeforces 810C Do you want a date? 思维
- Codeforces 810C Do you want a date?【思维】
- 810C. Do you want a date?
- Codeforces Round #415 C. Do you want a date?
- codeforces round #415 C.Do you want a Date?
- codeforces——809A/810C——Do you want a date?
- C. Do you want a date?
- codeforces 810C Do you want a date? 数学 快速幂取模
- 【Codeforces 809 A. Do you want a date?】
- Codeforces 809A Do you want a date?
- Codeforces Round #415 (Div. 2)-C. Do you want a date?
- Codeforces Round #415 (Div. 2)C. Do you want a date? (数学归纳)
- Codeforces Round #415 (Div. 2) C. Do you want a date? 数学
- Codeforces Round #415 (Div. 2) C. Do you want a date?
- Codeforces Round #415 (Div. 2) C. Do you want a date?
- 横向打印二叉树
- 牛客网(第三场)编程题
- HDU
- 将一组数分为相等的两组数
- xcode pod文件不提示 $(PODS_ROOT)"
- Codeforces 810C Do you want a date? 题解
- HDU
- Coin Toss(UVA
- VS2010 语法错误: 标识符“__RPC__out_xcount_part” 解决方法
- Math类
- AVL树详解
- CodeForces
- HDU
- shell中单引号、双引号、反引号的区别