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 ...
随机推荐
- notepad++列模式
考虑下面的情况: 已有 AAA BBB CCC 和 aaa bbb ccc 想合并为 AAA aaa BBB bbb CCC ccc 在大写后面,列模式,复制小写,粘贴,结果不是如下: AAA aaa ...
- HDU 1251 统计难题 (Trie)
pid=1251">统计难题 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/ ...
- 软件开发工具GCC
重点掌握以下知识点: 了解gcc编译器的下载和安装方法,包括嵌入式交叉编译平台搭建的方法 重点掌握gcc的基本编译流程和编译方法 重点掌握gcc编译的高级操作及选项 了解gcc编译器性能分析工具,包括 ...
- Android DataBinding库(MVVM设计模式)
什么是MVVM 说到DataBinding,就有必要先提起MVVM设计模式.Model–View–ViewModel(MVVM) 是一个软件架构设计模式,相比MVVM,大家对MVC或MVP可能会更加熟 ...
- Python模块学习 ---- logging 日志记录
许多应用程序中都会有日志模块,用于记录系统在运行过程中的一些关键信息,以便于对系统的运行状况进行跟踪.在.NET平台中,有非常著名的第三方开源日志组件log4net,c++中,有人们熟悉的log4cp ...
- 正确用DD测试磁盘读写速度
转自:http://blogread.cn/it/article/6479?f=wb 问: 以下几种方式测试磁盘读写速度有什么区别? dd bs=1M count=128 if=/dev/zero o ...
- (hdu step 6.3.3)Air Raid(最小路径覆盖:求用最少边把全部的顶点都覆盖)
题目: Air Raid Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total ...
- Zabbix Server和MPM(monitor for mysql)的高速部署
1. 前言 zabbix作为开源免费的监控软件.其易于管理配置和可视化的视图.历史数据的定期维护.模板化的监控项目越来越受到广大IT运维人员的喜爱. 这里主要是总结了下Zabbix S ...
- js获取事件源及触发该事件的对象
怎样获取事件源及触发该事件的对象,方法有非常多,js中能够通过event来实现.以下有个不错的演示样例,感兴趣的朋友能够參考下: function myfunction(event) { event ...
- yum groupinstall报错,处理方法
http://www.cnblogs.com/xiaoluo501395377/archive/2013/05/21/3089970.html ===== 创建repo库 # createrepo - ...