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 ...
随机推荐
- python 相似语句匹配(非机器学习)
#coding=utf-8 import xlrd import distance from sklearn.feature_extraction.text import CountVectorize ...
- 【pyhon】Python里的字符串查找函数find和java,js里的indexOf相似,找到返回序号,找不到返回-1
# 例子: target='www.163.com' ')) ')==-1: print('263不存在于字符串'+target+'中') 运行: C:\Users\horn1\Desktop\pyt ...
- RMSE均方根误差学习笔记
1.均方根误差,它是观测值与真值偏差的平方和观测次数n比值的平方根,在实际测量中,观测次数n总是有限的,真值只能用最可信赖(最佳)值来代替.方根误差对一组测量中的特大或特小误差反映非常敏感,所以,均方 ...
- python 网络请求类库 requests 使用
python 网络请求类库 requests 使用 requests是 为python封装的强大 REST 操作类库 githubhttps://github.com/kennethreitz/req ...
- WPF显示经常使用的几个显示文字控件TextBox, TextBlock, Lable
TextBox, TextBlock. Lable 当中TextBox 和Lable均继承了Control类 能够对其进行模板编辑. 而TextBlock没有继承Control所以不能对其进行模板编辑 ...
- Java微信扫描支付模式二Demo ,整合官网直接运行版本
概述 场景介绍 用户使用微信“扫一扫”扫描二维码后,获取商品支付信息,引导用户完成支付. 详细 代码下载:http://www.demodashi.com/demo/13880.html 一.相关配置 ...
- 每秒处理3百万请求的Web集群搭建-用 LVS 搭建一个负载均衡集群
这篇文章是<打造3百万次请求/秒的高性能服务器集群>系列的第3部分,有关于性能测试工具以及优化WEB服务器部分的内容请参看以前的文章. 本文基于你已经优化好服务器以及网络协议栈的基础之上, ...
- Linux命令-目录处理命令:rmdir
rmdir /tmp/shijiazhuang/yuhuaqu 删除一个子目录(必须是空目录) rmdir /tmp/shijiazhuang 删除一个不为空的目录会失败
- Linux命令-权限管理命令:umask
umask -S 显示用户创建目录或文件时的默认权限 mkdir shuaige 创建一个shuaige目录 ls -ld shuaige 查看shuaige目录当前的权限(和上面默认的权限是一样的) ...
- C#获取显示器屏幕数量 控制winform显示到哪一个屏幕
获取当前系统连接的屏幕数量: Screen.AllScreens.Count();获取当前屏幕的名称:string CurrentScreenName = Screen.FromControl(thi ...