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 ...
随机推荐
- Java中将String转json对象
import org.json.simple.JSONObject; import org.json.simple.parser.JSONParser; import org.json.simple. ...
- 一、 Hbase特性 3v特性,Volume(量级) Varity(种类) Velocity(速度)
HBase中表的特点 大: 一个表可以由百亿行,上百万列(列多时,插入变慢) 面向列:面向列(族)的存储和权限控制,列(族)独立检索 稀疏:对于为空(null) 的列,并不占用存储空间,因此表可以设计 ...
- cocos2d-x 3.1 学习(一):工具安装与配置环境
初级学习cocos2d-x 3.1开发,学习开发过程记录到博客上面来,哪写的不正确请指点. 1.工具安装 cocos2d-x 3.1rc0 最新版本号,下载后解压.下载地址:http://www.co ...
- 影响FPGA设计中时钟因素的探讨。。。转
http://www.fpga.com.cn/advance/skill/speed.htm http://www.fpga.com.cn/advance/skill/design_skill3.ht ...
- vim 基础学习之文件跳转
1. ''-当前文件上次跳转之前的位置2. '.-当前文件上次修改的位置,只要是发生了可能导致变化的命令操作就会被标记,哪怕实际结果没有变化3. '^-当前文件上次插入的位置,只要是发生了插入操作命令 ...
- Android Design Support Library(一)用TabLayout实现类似网易选项卡动态滑动效果
这里我们用TabLayout来实现这一效果.TabLayout是Android Design Support Library库中的控件.Google在2015的IO大会上,给我们带来了更加详细的Mat ...
- excel操作小技巧
excel拼接sql语句时,时间格式问题 问题:若直接插入时间的单元格 :="insert into t_entity_car (create_time,name,age) value (' ...
- angularjs之手机输入法回车变搜索,并触发事件,兼容pc回车事件
一.效果:回车按钮变搜索 之前的输入法: 之后的输入法: 二.功能实现 <input type="search" id="search_input" pl ...
- 实现人脸识别性别之路---opencv
import cv2from make_imge import get_file_namefrom train_ph import Modelimport os IMAGE_SIZE = 128if ...
- caioj 1063 动态规划入门(一维一边推1:美元和马克)
这道题一开始我是这么想的 最后的答案肯定是某次的马克换回来的,但这个该怎么确定?? 实际上应该把范围缩小,只看最后一次和倒数第二次之间有什么联系. 可以发现,只有两种可能,最后一天换或者不换.换的话就 ...