20141001 【 高精度 】 2014-上海区域赛-网络预选赛 hdoj 5047 Sawtooth
来源:互联网 发布:怎么加入淘宝联盟 编辑:程序博客网 时间:2024/05/16 13:01
Online JudgeOnline ExerciseOnline TeachingOnline ContestsExercise AuthorF.A.Q
Hand In Hand
Online Acmers
Forum | Discuss
Statistical ChartsBest Coder beta
VIP | STD Contests
Virtual Contests
DIY | Web-DIY beta
Recent Contests
Total Submission(s): 1106 Accepted Submission(s): 430
Statistic | Submit | Discuss | Note
Home | TopHangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2014 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.007610(s) query 7, Server time : 2014-10-01 10:04:13, Gzip disabledAdministration
Hand In Hand
Online Acmers
Forum | Discuss
Statistical ChartsBest Coder beta
VIP | STD Contests
Virtual Contests
DIY | Web-DIY beta
Recent Contests
wilson1068
Mail 0(0)
Control Panel
Sign Out
Mail 0(0)
Control Panel
Sign Out
Sawtooth
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1106 Accepted Submission(s): 430
Problem Description
Think about a plane:
● One straight line can divide a plane into two regions.
● Two lines can divide a plane into at most four regions.
● Three lines can divide a plane into at most seven regions.
● And so on...
Now we have some figure constructed with two parallel rays in the same direction, joined by two straight segments. It looks like a character “M”. You are given N such “M”s. What is the maximum number of regions that these “M”s can divide a plane ?
● One straight line can divide a plane into two regions.
● Two lines can divide a plane into at most four regions.
● Three lines can divide a plane into at most seven regions.
● And so on...
Now we have some figure constructed with two parallel rays in the same direction, joined by two straight segments. It looks like a character “M”. You are given N such “M”s. What is the maximum number of regions that these “M”s can divide a plane ?
Input
The first line of the input is T (1 ≤ T ≤ 100000), which stands for the number of test cases you need to solve.
Each case contains one single non-negative integer, indicating number of “M”s. (0 ≤ N ≤ 1012)
Each case contains one single non-negative integer, indicating number of “M”s. (0 ≤ N ≤ 1012)
Output
For each test case, print a line “Case #t: ”(without quotes, t means the index of the test case) at the beginning. Then an integer that is the maximum number of regions N the “M” figures can divide.
Sample Input
212
Sample Output
Case #1: 2Case #2: 19
Source
2014 ACM/ICPC Asia Regional Shanghai Online
Recommend
hujie | We have carefully selected several similar problems for you: 5056 5055 5054 5053 5052
Copyright © 2005-2014 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.007610(s) query 7, Server time : 2014-10-01 10:04:13, Gzip disabledAdministration
恶心的卡IO。
java 常用的 Scanner IO 方法会超时。
要用缓冲区优化。
当然,最好是用 C++ 大数模板上。
import java.math.*;import java.util.*;import java.io.*;public class Main {public static void main(String[] args) throws Exception {BufferedReader sc = new BufferedReader(new InputStreamReader(System.in)); PrintWriter out = new PrintWriter(System.out, true);BigInteger n, ans, a1, a2, a7, a8;a1 = BigInteger.valueOf(1);a2 = BigInteger.valueOf(2);a7 = BigInteger.valueOf(7);a8 = BigInteger.valueOf(8);String ss;ss = sc.readLine();int T;T = Integer.parseInt(ss);for(int i=1; i<=T; i++){ss = sc.readLine();n = new BigInteger(ss);out.print("Case #"+i+": ");if( n.equals(a1) ){out.println("2");continue;}else if( n.equals(a2) ){out.println("19");continue;}ans = n.multiply(n).multiply(a8);ans = ans.subtract(a7.multiply(n));ans = ans.add(a1);out.println( ans );}}}
这里优化了一下。
(上面的跑了1800+ms,下面的跑了1300+ms)
——————————————————
输入用 BufferedReader( cin ) 读入。
输出用 BufferedWriter( cout ) 写出。
这里 cout.write() 方法支持输出基本数据类型,
但不支持 BigInteger 和 BigDecimal 数据类型。
因此要先转化成 String 类型。
同时, cout.write() 不带回车。
你可以用 转义字符 '\n' 或 cout.newLine() 方法加上回车。
【Important】cout.write() 只是把其中的数据暂存起来(暂存在 cout 中),并没有输出。
想要输出数据,必须调用 cout.flush() 方法(清空 cout ,输出里面的数据)。
import java.math.*;import java.util.*;import java.io.*;public class Main {public static void main(String[] args) throws Exception {BufferedReader cin = new BufferedReader(new InputStreamReader(System.in)); BufferedWriter cout = new BufferedWriter(new OutputStreamWriter(System.out));BigInteger n, ans, a1, a2, a7, a8;a1 = BigInteger.valueOf(1);a2 = BigInteger.valueOf(2);a7 = BigInteger.valueOf(7);a8 = BigInteger.valueOf(8);String ss = cin.readLine();int T = Integer.parseInt(ss);for(int i=1; i<=T; i++){ss = cin.readLine();n = new BigInteger( ss );cout.write( "Case #"+i+": " );ans = n.multiply(n).multiply(a8);ans = ans.subtract(a7.multiply(n));ans = ans.add(a1);cout.write( ans.toString() );cout.newLine();cout.flush();}}}
0 0
- 20141001 【 高精度 】 2014-上海区域赛-网络预选赛 hdoj 5047 Sawtooth
- 20140930 【 DP - 状态压缩 】 2014-上海区域赛-网络预选赛 hdoj 5045 Contest
- 20140930 【 数论 -- 本福特定律 】 2014-上海区域赛-网络预选赛 hdoj 5051 Fraction
- HDOJ 5047 Sawtooth(Java高精度)
- 【HDU】5047 Sawtooth 高精度
- 2014上海网络预选赛1003(树链剖分)HDU5044
- 2014上海网络预选赛1011(LCT)HDU5052
- Hdu 5047 Sawtooth (平面分割) (2014上海Online)
- 2014 ACM-ICPC亚洲区域赛牡丹江站网络预选赛 CUntrusted Patrol
- 【大数问题】 HDOJ 5047 Sawtooth
- hdu5047(上海网赛1006)Sawtooth
- hdu5047(上海网赛1006)Sawtooth
- hdu 5047 Sawtooth 组合数学 高精度
- ZOJ 3814 / 2014 牡丹江赛区网络赛 F. Sawtooth Puzzle
- hdu 5047 Sawtooth--2014acm上海赛区邀请赛(附java模板)
- 校赛网络预选赛小结
- 杭电4011 亚洲区域赛上海赛区网络热身赛
- 2014 ACM/ICPC 上海区域赛小记
- 资讯的低准确相似文档——Lucene的MoreLikeThis
- javascript动画基础(四)--三角学在动画中的运用(3)
- 第一章数据结构思维导图
- C++ dynamic binding
- js 控制在关闭ie的提醒
- 20141001 【 高精度 】 2014-上海区域赛-网络预选赛 hdoj 5047 Sawtooth
- windows下搭建Eclipse+android4.0开发环境
- 【HDU 5052】Yaoge’s maximum profit【树链刨分】
- Android中的布局优化方法
- 单调队列的应用
- ios storyboard 视图跳转
- 面试-斐波那契数列
- 大学(一)
- Harvard statistics 110, video 1 note(probability & counting)