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 ...
随机推荐
- dedecms织梦自增索引标签
在列表中我们经常会需要动态的索引值,那么就可以用到如下标签 [field:global.autoindex/] 默认是从1开始,如果我们想从0或者从其他数开始如下: [field:autoindex ...
- HTML5 defer和async的区别
在HTML页面中插入Javascript的主要方法,就是使用<script>元素.这个元素由Netscape创造并在Netscape Navigator 2中首先实现.后来,这个元素就被加 ...
- 重启虚拟目录或站点,不重启iis
更改站点或虚拟目录的.net Framework 版本会导致重启整个iis服务,所以需要单独重启某个站点或虚拟目录 首先右键点击网站-所有任务-将配置保存到一个文件,从文件中查找到 Location ...
- 5 THINGS TOP BUG BOUNTY HUNTERS DO DIFFERENTLY
出处:https://www.hackerone.com/blog/5-things-top-bug-bounty-hunters-do-differently 本周,我们有幸收容了50名比利时科技学 ...
- Project Euler Problem4
Largest palindrome product Problem 4 A palindromic number reads the same both ways. The largest pali ...
- Linux umount的device is busy问题
现象: [root@dbserver ~]# df -h文件系统 容量 已用 可用 已用%% 挂载点/dev/vda1 9.9G 3.9G 5.6G 41% /tmpfs 3.9G 100K 3.9G ...
- 使用 Application Loader提交IPA文件到苹果市场
打包.导出ipa包后剩下的就是要将ipa包推到appstore.Application Loader是苹果提供的ipa包提交工具. 1.启动Application Loader 打开xcode,在xc ...
- _findfirst和_findnext
1.首先是_finddata结构体,用于存储文件信息的结构体. 2._findfirst函数:long _findfirst(const char *, struct _finddata_t *); ...
- Linux学习笔记:sed删除、插入数据
一.sed删除文件第一行 sed -i '1d' file.txt -- 删除第一行 sed -i 'nd' file.txt -- 删除第n行 sed -i '$d' file.txt -- 删除最 ...
- MVC的博客
一个基于Asp.net MVC的博客类网站开源了! 背景说明: 大学时毕业设计作品,一直闲置在硬盘了,倒想着不如开源出来,也许会对一些人有帮助呢,而且个人觉得这个网站做得还是不错了,毕竟是花了不少 ...