WHU 1470 Join in tasks 水题
http://acm.whu.edu.cn/land/problem/detail?problem_id=1470
大概是给你一个队列,每次移动队头的数到队尾并减1,如果本身这个数为1就删去. 然后ans += 这个数 * (队列长度-1),求最小的ans
只要最小的元素最先删除就能保证结果最小
解法:
先对原数列排序 然后模拟原操作 ...但是t[i] 太大 .显然不能一个个的模拟...其实稍微推一下就能得出 每次到达能删除元素的时候 整个队列循环了t[i]-1次...
我们维护一下后缀和suffix...就能得到这个公式:

前面等差数列,后面等差数列O(1)就能求出 总共n个数,总共O(n)
Notice : 等差数列里面/2不能随意取模,我们要对2求1e9+7的逆元再取模
过程举例: 2 3 4 5 6
第一轮: 2 3 4 5 6 to 1 2 3 4 5
第二轮: 2 3 4 5 to 1 2 3 4
第三轮: 2 3 4 to 1 2 3
第四轮: 2 3 to 2
第五轮: 2 (结果懒得写了...自己可以拍一下)
/********************* Template ************************/
#include <set>
#include <map>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std; #define EPS 1e-8
#define MAXN 100005
#define MOD ((int)1e9+7)
#define PI acos(-1.0)
#define DINF (1e10)
#define LINF ((1LL)<<50)
#define INF (0x3f3f3f3f)
#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) < (b) ? (a) : (b))
#define max3(a,b,c) (max(max(a,b),c))
#define min3(a,b,c) (min(min(a,b),c))
#define BUG cout<<"BUG! "<<endl
#define line cout<<"--------------"<<endl
#define L(t) (t << 1)
#define R(t) (t << 1 | 1)
#define Mid(a,b) ((a + b) >> 1)
#define lowbit(a) (a & -a)
#define FIN freopen("in.txt","r",stdin)
#define FOUT freopen("out.txt","w",stdout)
#pragma comment (linker,"/STACK:102400000,102400000") typedef long long LL;
typedef unsigned long long ULL;
// typedef __int64 LL;
// typedef unisigned __int64 ULL;
// LL gcd(LL a,LL b){ return b?gcd(b,a%b):a; }
// LL lcm(LL a,LL b){ return a*b/gcd(a,b); } /********************* F ************************/
LL suf;
LL a[MAXN];
LL r2 = ()/+;
int main()
{
int T;
scanf("%d",&T);
int cas = ;
for(int cas = ; cas <= T; cas++){
suf = ;
int n,num;
scanf("%d",&n);
num = n-;
for(int i = ; i < n ; i++)
scanf("%lld",&a[i]);
sort(a,a+n);
for(int i = ; i < n ; i++){
suf += a[i];
}
LL res = ;
LL ct = ;
for(int i = ; i < n- ; i++){
a[i] = a[i] - ct;
res = (res + ((a[i]+)%MOD*a[i]%MOD*r2%MOD*num%MOD))%MOD;
int cnt = a[i] - ;
if(cnt > ){
LL sum = (suf + (suf - (cnt-) * num)) % MOD * cnt % MOD * r2 % MOD;
res = (res + (sum*num)%MOD) % MOD;
}
suf -= (num * cnt);
suf = suf - ((a[i+]-ct) - cnt);
num--;
ct += cnt;
}
printf("Case %d: ",cas);
printf("%lld\n",res);
}
return ;
}
WHU 1470 Join in tasks 水题的更多相关文章
- Uva 10305 - Ordering Tasks 拓扑排序基础水题 队列和dfs实现
今天刚学的拓扑排序,大概搞懂后发现这题是赤裸裸的水题. 于是按自己想法敲了一遍,用queue做的,也就是Kahn算法,复杂度o(V+E),调完交上去,WA了... 于是检查了一遍又交了一发,还是WA. ...
- Codeforces Round #334 (Div. 2) A. Uncowed Forces 水题
A. Uncowed Forces Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/604/pro ...
- HDU 4593 H - Robot 水题
H - RobotTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.act ...
- Atcoder 水题选做
为什么是水题选做呢?因为我只会水题啊 ( 为什么是$Atcoder$呢?因为暑假学长来讲课的时候讲了三件事:不要用洛谷,不要用dev-c++,不要用单步调试.$bzoj$太难了,$Topcoder$整 ...
- Lightoj 1112 - Curious Robin Hood 【单点改动 + 单点、 区间查询】【树状数组 水题】
1112 - Curious Robin Hood PDF (English) Statistics Forum Time Limit: 1 second(s) Memory Limit: 64 MB ...
- HDOJ 2317. Nasty Hacks 模拟水题
Nasty Hacks Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tota ...
- ACM :漫漫上学路 -DP -水题
CSU 1772 漫漫上学路 Time Limit: 1000MS Memory Limit: 131072KB 64bit IO Format: %lld & %llu Submit ...
- ytu 1050:写一个函数,使给定的一个二维数组(3×3)转置,即行列互换(水题)
1050: 写一个函数,使给定的一个二维数组(3×3)转置,即行列互换 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 154 Solved: 112[ ...
- [poj2247] Humble Numbers (DP水题)
DP 水题 Description A number whose only prime factors are 2,3,5 or 7 is called a humble number. The se ...
随机推荐
- JavaScript:理解prototype与__proto__,原型与原型链
JS中的继承是原型继承,通过原型实现的.为了理解原型,我想先讲讲对象的内部属性[[prototype]]和属性__proto__,函数的属性prototype. 对象的内部属性[[prototype] ...
- hdu 5412 CRB and Queries(整体二分)
题意 动态区间第k大 (n<=100000,m<=100000) 题解 整体二分的应用. 与静态相比差别不是很大.(和CDQ还有点像)所以直接上代码. #include<iostre ...
- [USACO12MAR]摩天大楼里的奶牛(状态压缩DP)
题意 给出n个物品,体积为w[i],现把其分成若干组,要求每组总体积<=W,问最小分组.(n<=18) 题解 一看以为是弱智题.(可能真的是,我太菜了) 然后跟walthou夸下海口:这么 ...
- 01-JS起步
01-JS起步
- ArcGIS api for javascript——图层-创建WMS图层类型的图层
本例使用一个WMS端点创建了一个简单的动态图层.首先,代码声明一个新的类my.CityStatesRiversUSAWMSLayer,该类继承esri.layers.DynamicMapService ...
- C语言之基本算法26—佩尔方程求解
//穷举法! /* ====================================================== 题目:求佩尔方程x*x-73*y*y=1的解. =========== ...
- !HDU 2602 Bone Collector--DP--(裸01背包)
题意:这题就是一个纯粹的裸01背包 分析:WA了好几次.01背包实现的一些细节没搞懂 1.为什么dp[i][j]赋初值为0而不是value[i].由于第i个石头可能不放! 2.在进行状态转移之前要dp ...
- POJ 1167 The Buses 暴搜+剪枝
思路: 先把能选的路线都预处理出来 按照能停的车的多少排个序 (剪枝1) 搜搜搜 如果当前剩的车÷当前能停车的多少+deep>=ans剪掉 (剪枝2) //By SiriusRen #inclu ...
- Windows安全攻略:教你完全修复系统漏洞
Windows安全攻略:教你完全修复系统漏洞 首发:http://safe.it168.com/a2012/0709/1369/000001369740.shtml 目前互联网上的病毒集团越来越猖狂, ...
- 日天的终生大事(dp)
日天的终生大事 题目描述 日天学长向妹子表白了,妹子说:“日天你那么聪明,回答我一个问题就答应你.你告诉我,L位K进制数有多少个?”日天表示这个问题太简单了,要求提高难度.妹子想了想说:“那么我增加一 ...