Xtreme8.0 - Sum it up 水题
Sum it up
题目连接:
https://www.hackerrank.com/contests/ieeextreme-challenges/challenges/sum-it-up
Description
Minka is very smart kid who recently started learning computer programming.
His coach gave him a cyclic array A having N numbers, and he has to perform Q operations on this array.
In each operation the coach would provide him with a number X. After each operation, every element of the cyclic array would be replaced by the sum of itself and the element lying X positions behind it in the cyclic array. All these replacements take place simultaneously.
For example, if the cyclic array was [a, b, c, d], then after the operation with X = 1, the new array would be [a+d, b+a, c+b, d+c].
He needs to output the sum of the elements of the final array modulus 10^9+7.
He made a program for it but it's not very efficient. You know he is a beginner, so he wants you to make an efficient program for this task because he doesn't want to disappoint his coach.
Input
The first line of each test file contains a integer N (1 <= N <= 100000).
The next line contains N space separated integers which represent the elements of the cyclic array ( 1 <= Ai <= 10^9 ).
The third line contains a integer Q (0 <= Q <= 1000000) representing the number of operations that will be applied to the array.
Finally, Q lines follow, each one containing an integer X (0 <= X < N).
Output
Your program should output to the standard output stream the sum of the elements of the final array modulus 10^9+7.
Note: There is a newline character at the end of the last line of the output.
Sample Input
5
1 2 3 4 5
2
1
0
Sample Output
60
Hint
题意
给你n个数,然后有Q次操作
每次操作是让a[i]+=a[(i+x)%n]
最后问你所有数的和是多少
题解
一个个去想的话,感觉不可做
但是你从整体去思考的话,那么显然就是一个傻逼题了。
代码
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+7;
const int mod = 1e9+7;
int a[maxn];
int main()
{
int n,m;scanf("%d",&n);
long long ans = 0,sum = 0;
for(int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
sum+=a[i],sum%=mod;
}
scanf("%d",&m);
for(int i=1;i<=m;i++){
int x;
scanf("%d",&x);
sum=(sum+sum)%mod;
}
cout<<sum<<endl;
}
Xtreme8.0 - Sum it up 水题的更多相关文章
- HDU5053the Sum of Cube(水题)
HDU5053the Sum of Cube(水题) 题目链接 题目大意:给你L到N的范围,要求你求这个范围内的全部整数的立方和. 解题思路:注意不要用int的数相乘赋值给longlong的数,会溢出 ...
- hdu5003 Osu!排序实现水题
Osu! is a famous music game that attracts a lot of people. In osu!, there is a performance scoring s ...
- ZOJ 2679 Old Bill ||ZOJ 2952 Find All M^N Please 两题水题
2679:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1679 2952:http://acm.zju.edu.cn/onli ...
- Xtreme8.0 - Magic Square 水题
Xtreme8.0 - Magic Square 题目连接: https://www.hackerrank.com/contests/ieeextreme-challenges/challenges/ ...
- codeforces 577B B. Modulo Sum(水题)
题目链接: B. Modulo Sum time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- poj1564 Sum It Up dfs水题
题目描述: Description Given a specified total t and a list of n integers, find all distinct sums using n ...
- UVa 10970 - Big Chocolate 水题 难度: 0
题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...
- SPOJ 3693 Maximum Sum(水题,记录区间第一大和第二大数)
#include <iostream> #include <stdio.h> #include <algorithm> #define lson rt<< ...
- poj 1003:Hangover(水题,数学模拟)
Hangover Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 99450 Accepted: 48213 Descri ...
随机推荐
- hdu 4857 Little Devil I
http://acm.hdu.edu.cn/showproblem.php?pid=4897 题意:给你一棵树,边的颜色要么为白色,要么为黑色,初始每条边为白色,有三种操作 1.将u-v链上面的所有边 ...
- Python核心编程——Chapter16
好吧,在拜读完<Python网络编程基础>之后,回头再搞一搞16章的网络编程吧. Let‘s go! 16.4.修改书上示例的TCP和UDP客户端,使得服务器的名字不要在代码里写死,要允许 ...
- A*算法改进——Any-Angle Path Planning的Theta*算法与Lazy Theta*算法
本文是该篇文章的归纳http://aigamedev.com/open/tutorial/lazy-theta-star/#Nash:07 . 传统的A*算法中,寻找出来的路径只能是沿着给出的模型(比 ...
- tf.range()函数
range()函数用于创建数字序列变量,有以下两种形式: range(limit, delta=1, dtype=None, name='range') range(start, limit, del ...
- c++刷题(39/100)笔试题3
题目1: 现在你需要用一台奇怪的打字机书写一封书信.信的每行只能容纳宽度为100的字符,也就是说如果写下某个字符会导致行宽超过100,那么就要另起一行书写 信的内容由a-z的26个小写字母构成,而每个 ...
- asp.net(c#)中相对路径(虚拟路径)和物理磁盘路径的转换
物理路径:磁盘路径,也就是在磁盘上的位置. 虚拟路径:web页面上的路径,是相对于应用程序而言的. /// 将物理路径转换成相对路径 /// </summary> ...
- vb 中recordset提示对象关闭时不允许操作
vb中执行查询后,一般要判断是否为空,只要执行的查询执行了select,都可以用rs.eof 或者 rs.recordcount来判断, 但是,如果执行的sql中加了逻辑判断,导致没有执行任何sele ...
- (AC自动机)C - 病毒侵袭持续中
题目链接:https://cn.vjudge.net/contest/280743#problem/C 题目大意:中文题 具体思路:首先取ascii码0-130是肯定不行的了,会超时.然后就开始简化, ...
- 操作系统环境变量LANG和NLS_LANG的关系
=Native Language Support本地语言支持 NLS ORACLE11g-ORA-12705: Cannot access NLS data files or invalid envi ...
- 细说MySQL备份的基本原理(系列一 ) 备份与锁
数据库作为一个系统中唯一或者主要的持久化组件,对服务的可用性和数据的可靠性要求极高. 作为能够有效应对因为系统软硬件故障.人工误操作导致数据丢失的预防手段,备份是目前最为常见的数据库运维操作. 考虑到 ...