The 14th UESTC Programming Contest Final B - Banana Watch 预处理、前缀和
B - Banana Watch
Time Limit: 1000/1000MS (Java/Others) Memory Limit: 262144/262144KB (Java/Others)
Status
As a famous technology company, Banana Inc. invents Banana Watch, redefining the watch.
While a normal watch has 12 indexes
and two or three moving hands, a Banana Watch has n indexes
and a moving hand.
The moving hand is at 0 initially,
and in 1st second,
it turns 1 index
clockwise; in 2nd second,
it turns 2 indexes
clockwise; ... ;
in ith second,
it turns
i indexes
clockwise. When it moves back to 0 exactly,
one minute passes (Yes, Banana Inc. also redefines the minute).
How many seconds in the first minute?
Input
One integer n.
3≤n≤106
Sample input and outputOutput
Print the number of seconds in the first minute.
| Sample Input | Sample Output |
|---|---|
3 |
2 |
5 |
4 |
Hint
If n=5,
in 1st second,
the hand moves to 1;
in 2nd second,
the hand moves to 3;
in 3rd second,
the hand moves to 1;
in 4th second,
the hand moves to 0.
So the answer for n=5 is 4.
My Solution
用sum[i]表示1~i的和,然后,从1 ~ maxn 查找。第一次出现if((sum[i] %= n) == 0) {printf("%d", i); break;}
然后考虑到数据范围。所以第一发有maxn = 2000000 + 1000,然后就过了。
假设用 1000000 + 8可能过也可能过不了。
#include <iostream>
#include <cstdio>
using namespace std;
const int maxn = 2000000 + 1000;
long long sum[maxn];
int main()
{
int n;
scanf("%d", &n);
sum[0] = 0;
for(int i = 1; i < maxn; i++){
sum[i] += sum[i-1]+i;
if((sum[i] %= n) == 0) {printf("%d", i); break;}
}
return 0;
}
Thank you!
The 14th UESTC Programming Contest Final B - Banana Watch 预处理、前缀和的更多相关文章
- The 16th UESTC Programming Contest Final 游记
心情不好来写博客. 为了满足ykk想要气球的愿望,NicoDafaGood.Achen和我成功去神大耍了一圈. 因为队名一开始是LargeDumpling应援会,然后队名被和谐,变成了学校的名字,顿时 ...
- The 15th UESTC Programming Contest Preliminary J - Jermutat1on cdoj1567
地址:http://acm.uestc.edu.cn/#/problem/show/1567 题目: Jermutat1on Time Limit: 3000/1000MS (Java/Others) ...
- The 15th UESTC Programming Contest Preliminary C - C0ins cdoj1554
地址:http://acm.uestc.edu.cn/#/problem/show/1554 题目: C0ins Time Limit: 3000/1000MS (Java/Others) M ...
- The 15th UESTC Programming Contest Preliminary B - B0n0 Path cdoj1559
地址:http://acm.uestc.edu.cn/#/problem/show/1559 题目: B0n0 Path Time Limit: 1500/500MS (Java/Others) ...
- The 15th UESTC Programming Contest Preliminary K - Kidd1ng Me? cdoj1565
地址:http://acm.uestc.edu.cn/#/problem/show/1565 题目: Kidd1ng Me? Time Limit: 3000/1000MS (Java/Others) ...
- The 15th UESTC Programming Contest Preliminary M - Minimum C0st cdoj1557
地址:http://acm.uestc.edu.cn/#/problem/show/1557 题目: Minimum C0st Time Limit: 3000/1000MS (Java/Others ...
- 2016 China Collegiate Programming Contest Final
2016 China Collegiate Programming Contest Final Table of Contents 2016 China Collegiate Programming ...
- 2018 China Collegiate Programming Contest Final (CCPC-Final 2018)-K - Mr. Panda and Kakin-中国剩余定理+同余定理
2018 China Collegiate Programming Contest Final (CCPC-Final 2018)-K - Mr. Panda and Kakin-中国剩余定理+同余定 ...
- The 15th UESTC Programming Contest Preliminary G - GC?(X,Y) cdoj1564
地址:http://acm.uestc.edu.cn/#/problem/show/1564 题目: G - GC?(X,Y) Time Limit: 3000/1000MS (Java/Others ...
随机推荐
- SQL Server更改排序规则的实现过程
摘自: http://www.2cto.com/database/201112/115138.html 以下的文章主要向大家描述的是SQL Server更改排序规则的实现过程,以及在实现其实际操作过程 ...
- mssql Sqlver 修改标识列方法
摘自: http://www.cnblogs.com/badboy2008/articles/1145465.html MSSQL Server修改标识列方法 ----允许对系统表进行更新exec ...
- 使用ReportStudio打开cube模型创建报表出现两个最细粒度名称
本人也是第一次遇到这样的问题,此问题甚是简单,也许很简短的一句话就可以解决这个问题了,看官请留神哦 cube做好发布到cognos之后使用Analysis Studio打开结构正常 于是想到要用此数据 ...
- 扩展JQUERY 表单加载JSON数据
$.fn.extend({ //表单加载json对象数据 setForm : function (jsonValue) { var obj = this; $.each(jsonValue, func ...
- 截短字符串的函数(JS中适用)
function cutShort(str){ if(str.length>15){ str=str.substr(0,15)+"..."; } ...
- CSV 读写
using System; using System.IO; using System.Runtime.InteropServices; using UnityEngine; public class ...
- div浏览器兼容问题
1. 默认的内外边距不同 问题: 各个浏览器默认的内外边距不同 解决: *{margin:0;padding:0;} 2. 水平居中的问题 问题: 设置 text-align: center ie6- ...
- 编程算法 - 从1到n整数中1出现的次数 代码(C)
从1到n整数中1出现的次数 代码(C) 本文地址: http://blog.csdn.net/caroline_wendy 题目: 输入一个整数n, 求从1到n这n个整数的十进制表示中1出现的次数. ...
- 首次使用JBoss流程(windows下)
1.首先应该明白JBoss分为社区版(AS)和企业版(EAP),其中社区版已经改名wildfly(难道是野苍蝇的意思?),企业版对个人开发者免费下载使用, 这里由于公司要求,我用的是jboss-eap ...
- 转:sock_ev——linux平台socket事件框架(event dispatcher) .
最近比较忙,好久没更新了:今天我们看一下事件的监听方式,在linux下面事件的监听方式有三种select.poll.epoll,性能上面epoll最高,如果仅是最多监听十多个描述符,用啥无所谓,如果是 ...