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 ...
随机推荐
- 高性能CSS
避免使用@import 有两种方式加载样式文件,一种是link元素,另一种是CSS 2.1加入@import.而在外部的CSS文件中使用@import会使得页面在加载时增加额外的延迟.虽然规则允许在样 ...
- [Functional Programming] Working with two functors(Applicative Functors)-- Part2 --liftAN
Let's examine a pointfree way to write these applicative calls. Since we know map is equal to of/ap, ...
- HYSBZ 1012 最大数maxnumber
思路:在单调队列不更新列首.由于查询区间大小不确定,所以不能保证下次是否还用到它 #include <cstdio> #include <cstring> #include & ...
- 淘宝网前端开发面试题(一)--HTML & CSS 面试题
所有答案仅供参考,不负责答案对错(^_^) 1.DOCTYPE? 严格模式不混杂模式-如何触发这两种模式,区分它们有何意义? 分析: DOCTYPE(是DOCument TYPE的缩写,即文档类型)是 ...
- “建议127:Lock与synchronized是不一样的问题”实际验证
近期又一次翻看 "编写高质量代码:改善Java程序的151个建议" 一书的时候看到"建议127"的文章中作者提供的測试用例存在一些值得商榷的地方. 在使 ...
- AVAudioPlayer播放在线音频文件
AVAudioPlayer播放在线音频文件 一:原里: AVAudioPlayer是不支持播放在线音频的,但是AVAudioPlayer有一个 initWithData的方法:我们可以把在线音频转换为 ...
- .NET设计规范一:设计规范基础
http://www.cnblogs.com/yangcaogui/archive/2012/04/18/2447049.html 前一段时间阅读了“.NET设计规范”这本书,读后给我的感觉是规范对开 ...
- Tp框架中模板中if条件如何使用?
- JUnit 3.8 让所有测试程序 实现 复合的测试(TestSuite)
之前是单个单个程序测试,这种方式在测试类比较少的时候可行, 但测试类多了,单个单个的这个测试方式就不推荐了,那得使用 复合的测试了 一个TestSuite是一个复合的测试.它运行测试用例集. 这个 ...
- Java中try catch finally的执行顺序问题
finally 语句块是在 try 或者 catch 中的 return 语句之前执行的.更加一般的说法是,finally 语句块应该是在控制转移语句之前执行,控制转移语句除了 return 外,还有 ...