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 ...
随机推荐
- NSURLSession的作用
NSURLSession的作用: 1.全局配置: 2.任务生成与管理: 3.数据链接管理: po self.urlSession.delegateQueue.operations <__NSAr ...
- Xrdp - 通过Windows的RDP连接Linux远程桌面(Ubuntu/CentOS/Redhat 7)(转载)
您多久访问一次Linux桌面? 您使用什么工具来访问远程桌面? Xrdp是一个开源工具,允许用户通过Windows RDP访问Linux远程桌面. 除了Windows RDP之外,xr ...
- 链表python
无序链表.有序链表 有序列表排序通常是升序或降序,并且我们假设列表项具有已经定义的有意义的比较运算. 许多有序列表操作与无序列表的操作相同. 必须明确链表的第一项位置,一旦知道第一项. 链表实现的基本 ...
- d3 bubble源码分析
技术 d3.d3.pack.d3.hierarchy 展示 https://bl.ocks.org/xunhanliu/e0688dc2ae9167c4c7fc264c0aedcdd1 关于怎么使用, ...
- javascript实现多线程 Concurrent.Thread.js
在这次我的项目中,因为前端要检测硬件加载并识别,再向后台请求发送数据,然后再返回的相应的配置文件!在这过程,要好时好几秒钟,严重影响体验效果,所以在网上靠看的方案,运用多线程去处理,这效果明显改善! ...
- win2003系统同步Linux ntp server批处理
最后更新时间: 2018/12/15 一般windows配置时间服务器,只需要在windows系统右下角,点时间,里面配置好对应NTP服务器地址就行, 至多再修改一下注册表 HKEY_LOCAL_MA ...
- Python安装selenium启动浏览器
1:在Python运行火狐或谷歌的浏览器是需要下载相对应的驱动 例如:你想在Python中使用代码命令打开firefox的网页 如果没有安装驱动,直接运行的话会出下面的错误 所以我们要安装相对应的浏览 ...
- 【Educational Codeforces Round 37 B】 Tea Queue
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 用一个队列来模拟排队就好. 队列放三元组(x,y,z) x表示人的下标,y和z分别表示进入和退出时间. 然后枚举时间从1到5000 ...
- COGS——T1588. [USACO FEB04]距离咨询
http://cogs.pro/cogs/problem/problem.php?pid=1588 ★★ 输入文件:dquery.in 输出文件:dquery.out 简单对比时间限制:1 ...
- 洛谷 P1583 魔法照片
P1583 魔法照片 题目描述 一共有n(n≤20000)个人(以1--n编号)向佳佳要照片,而佳佳只能把照片给其中的k个人.佳佳按照与他们的关系好坏的程度给每个人赋予了一个初始权值W[i].然后将初 ...