CodeForces - 810C(规律)
2 seconds
256 megabytes
standard input
standard output
Leha decided to move to a quiet town Vičkopolis, because he was tired by living in Bankopolis. Upon arrival he immediately began to expand his network of hacked computers. During the week Leha managed to get access to n computers throughout the town. Incidentally all the computers, which were hacked by Leha, lie on the same straight line, due to the reason that there is the only one straight street in Vičkopolis.
Let's denote the coordinate system on this street. Besides let's number all the hacked computers with integers from 1 to n. So the i-th hacked computer is located at the point xi. Moreover the coordinates of all computers are distinct.
Leha is determined to have a little rest after a hard week. Therefore he is going to invite his friend Noora to a restaurant. However the girl agrees to go on a date with the only one condition: Leha have to solve a simple task.
Leha should calculate a sum of F(a) for all a, where a is a non-empty subset of the set, that consists of all hacked computers. Formally, let's denote A the set of all integers from 1 to n. Noora asks the hacker to find value of the expression . Here F(a) is calculated as the maximum among the distances between all pairs of computers from the set a. Formally,
. Since the required sum can be quite large Noora asks to find it modulo 109 + 7.
Though, Leha is too tired. Consequently he is not able to solve this task. Help the hacker to attend a date.
The first line contains one integer n (1 ≤ n ≤ 3·105) denoting the number of hacked computers.
The second line contains n integers x1, x2, ..., xn (1 ≤ xi ≤ 109) denoting the coordinates of hacked computers. It is guaranteed that all xi are distinct.
Print a single integer — the required sum modulo 109 + 7.
2
4 7
3
3
4 3 1
9
There are three non-empty subsets in the first sample test:,
and
. The first and the second subset increase the sum by 0 and the third subset increases the sum by 7 - 4 = 3. In total the answer is 0 + 0 + 3 = 3.
There are seven non-empty subsets in the second sample test. Among them only the following subsets increase the answer: ,
,
,
. In total the sum is (4 - 3) + (4 - 1) + (3 - 1) + (4 - 1) = 9.
题意就是n 个数 组成的2^n个集合 问每个集合的最大值减去最小值得和对1e9取模
其实 这题就是去a[i]这个数要加多少次 减多少次
a[1] a[2] a[3] a[4] a[5].....a[n] 排序后
对于a[1] 需要减2^0+2^1+2^2.....2^(n-i-1) 就是相当于(i j)(开区间)有多少个数
加多少个a[i]也可以推 2^0+2^1+...+2^(i-2)
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<cstring>
#include<map>
#include<stack>
#include<set>
#include<vector>
#include<algorithm>
#include<string.h>
typedef long long ll;
typedef unsigned long long LL;
using namespace std;
const int INF=0x3f3f3f3f;
const double eps=0.0000000001;
const int N=+;
const ll mod=1e9+;
ll a[N];
ll b[N];
void init(){
b[]=;
for(int i=;i<=N;i++){
b[i]=(b[i-]*)%mod;
}
}
int main(){
int n;
init();
while(scanf("%d",&n)!=EOF){
for(int i=;i<=n;i++)scanf("%I64d",&a[i]);
sort(a+,a+n+);
ll ans=;
for(int i=;i<=n;i++){
ans=(ans-a[i]*((b[n-i]-))%mod+mod)%mod;
ans=(ans+a[i]*(b[i-]-)%mod)%mod;
}
cout<<ans<<endl;
}
}
CodeForces - 810C(规律)的更多相关文章
- Codeforces 810C Do you want a date?(数学,前缀和)
C. Do you want a date? time limit per test:2 seconds memory limit per test:256 megabytes input:stand ...
- Integer Sequence Dividing CodeForces - 1102A (规律)
You are given an integer sequence 1,2,…,n1,2,…,n. You have to divide it into two sets AAand BB in su ...
- 【codeforces 810C】Do you want a date?
[题目链接]:http://codeforces.com/contest/810/problem/C [题意] 给你一个集合,它包含a[1],a[2]..a[n]这n个整数 让你求出这个集合的所有子集 ...
- CodeForces 22、23部分题解
CodeForces 22A 找严格第二小的...注意只有一种情况,可以sort排序然后unique输出. int a[N]; int main() { int n; while(~scanf(&qu ...
- codeforces D. Queue 找规律+递推
题目链接: http://codeforces.com/problemset/problem/353/D?mobile=true H. Queue time limit per test 1 seco ...
- Codeforces Gym 100015A Another Rock-Paper-Scissors Problem 找规律
Another Rock-Paper-Scissors Problem 题目连接: http://codeforces.com/gym/100015/attachments Description S ...
- Codeforces Round #347 (Div. 2) C. International Olympiad 找规律
题目链接: http://codeforces.com/contest/664/problem/C 题解: 这题最关键的规律在于一位的有1989-1998(9-8),两位的有1999-2098(99- ...
- Codeforces Round #327 (Div. 2) C. Median Smoothing 找规律
C. Median Smoothing Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/591/p ...
- Codeforces Gym 100114 A. Hanoi tower 找规律
A. Hanoi tower Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100114 Descript ...
随机推荐
- 解决Sql Server 日志满了,设置收缩
解决Sql Server 日志满了,设置收缩: --查看文件占用空间 . '文件大小(MB)',* from sysfiles; ALTER DATABASE SpyData SET RECOVERY ...
- dubbo之延迟暴露
延迟暴露 如果你的服务需要预热时间,比如初始化缓存,等待相关资源就位等,可以使用 delay 进行延迟暴露. 延迟 5 秒暴露服务 <dubbo:service delay="5000 ...
- C# WebKitBrowser 设置内容
WebKit.WebKitBrowser kitBrowser = new WebKit.WebKitBrowser(); kitBrowser.Dock = DockStyle.Fill; // k ...
- 黑苹果开启retina,大分辨率的方法
首先,管理分辨率RDM的软件这里下载: http://pan.baidu.com/s/1bpjL07P 在终端输入: curl -o ~/enable-HiDPI.sh https://raw.git ...
- CentOS下修改root用户名
修改root登录用户名减少Linux云主机“被暴力破解”警告,登录云主机的时候就先显示登录失败多少次.其是公网有人在扫用弱密码破解登录. 所谓暴力破解,就是用“用户名“+”密码”穷举的方式进行远程登录 ...
- IE浏览器new Date()带参返回NaN解决方法
var start = '2016-01-01 12:12:12'; var date = new Date(start); 得到的时间为NaN: 解决方法: 1.自定义方法 自定义一个NewDate ...
- STL源码分析之迭代器
前言 迭代器是将算法和容器两个独立的泛型进行调和的一个接口. 使我们不需要关系中间的转化是怎么样的就都能直接使用迭代器进行数据访问. 而迭代器最重要的就是对operator *和operator-&g ...
- enote笔记语言(4)(ver0.3)——“5w1h2k”分析法
章节:“5w1h2k”分析法 what:我想知道某个“关键词(keyword)”(即,词汇.词语,或称单词,可以是概念|专业术语|.......)的定义. why:我想知道事物发生的原因.“why ...
- Django REST framework 分页
三种分页:根据页码.根据索引.根据加密 http://www.xx.com/courses/?page=1&size=10 http://www.xx.com/courses/?offset= ...
- i++与++i的区别及效率
i++与++i的区别及效率 先看看基本区别:i++ :先在i所在的表达式中使用i的当前值,后让i加1++i :让i先加1,然后在i所在的表达式中使用i的新值 看一些视频教程里面写for循环的时候都 ...