acm_icpc網(wǎng)絡(luò)賽第六站:上海賽區(qū)(跪爛心已死)
來源:程序員人生 發(fā)布時間:2014-10-11 08:00:01 閱讀次數(shù):3896次
最后一站了,很無奈的是還是沒出線,最終3題結(jié)束,排名380 不得不承認自己不行,總覺著自己才弄了幾個月,然后各種為自己的弱找借口,不行就是不行,沒有借口,以后要更加努力了。廢話不多說了 Fighting!
1006:
Sawtooth
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 466 Accepted Submission(s): 152
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 ?
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)
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
Sample Output
Case #1: 2
Case #2: 19
遞推+大數(shù)
增加第n+1個 “M”時,交點最多有16n個,所以增加區(qū)域 16n+1個;
f(n+1)-f(n)=16*n+1;
f(1)=2;
解得
f(n)=n*(8*n-7)+1;
然后 直接上BigInteger 就行了 然后悲劇的是當時我不會java的輸入優(yōu)化結(jié)果出題人故意卡java。。最后隊友敲的數(shù)組模擬過的
下面上java輸入輸出優(yōu)化的代碼 很簡單~
import java.io.*;
import java.util.*;
import java.math.BigInteger;
public class Hello {
public static void main(String[] args) throws IOException{
StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
int t,cas=1;BigInteger n,a,b,c;
in.nextToken();
t=(int)in.nval;
for(int i=1;i<=t;i++){
in.nextToken();
long x=(long)in.nval;
n=BigInteger.valueOf(x);
a=new BigInteger("8");
b=new BigInteger("7");
c=new BigInteger("1");
BigInteger ans=a.multiply(n);
ans=ans.subtract(b);
ans=ans.multiply(n);
ans=ans.add(c);
out.println("Case #"+cas+": "+ans);cas++;
}
out.flush();//刷新緩沖區(qū) (必須)
out.close();
}
}
1009:
Divided Land
Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 133 Accepted Submission(s): 69
Problem Description
It’s time to fight the local despots and redistribute the land. There is a rectangular piece of land granted from the government, whose length and width are both in binary form. As the mayor, you must segment the land into multiple squares of equal size for the villagers. What are required is there must be no any waste and each single segmented square land has as large area as possible. The width of the segmented square land is also binary.
Input
The first line of the input is T (1 ≤ T ≤ 100), which stands for the number of test cases you need to solve.
Each case contains two binary number represents the length L and the width W of given land. (0 < L, W ≤ 21000)
Output
For each test case, print a line “Case #t: ”(without quotes, t means the index of the test case) at the beginning. Then one number means the largest width of land that can be divided from input data. And it will be show in binary. Do not have any useless number or space.
Sample Input
3
10 100
100 110
10010 1100
Sample Output
Case #1: 10
Case #2: 10
Case #3: 110
二進制下求a,b的最大公約數(shù) 還是BigInteger 由于一開始不知道BigInteger二進制的轉(zhuǎn)換 chp用模擬敲了半天也沒搞好 后來用java 10幾行解決了
import java.io.*;
import java.util.*;
import java.math.*;
import java.text.*;
public class Main {
public static void main(String[] args) {
Scanner in=new Scanner(System.in);
String a,b;int t,cas=1;
t=in.nextInt();
for(int i=0;i<t;i++){
a=in.next();
b=in.next();
BigInteger x=new BigInteger(a,2);
BigInteger y=new BigInteger(b,2);
System.out.print("Case #"+cas+": ");cas++;
System.out.println(x.gcd(y).toString(2));
}
}
}
1012:
the Sum of Cube
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 181 Accepted Submission(s): 114
Problem Description
A range is given, the begin and the end are both integers. You should sum the cube of all the integers in the range.
Input
The first line of the input is T(1 <= T <= 1000), which stands for the number of test cases you need to solve.
Each case of input is a pair of integer A,B(0 < A <= B <= 10000),representing the range[A,B].
Output
For each test case, print a line “Case #t: ”(without quotes, t means the index of the test case) at the beginning. Then output the answer
生活不易,碼農(nóng)辛苦
如果您覺得本網(wǎng)站對您的學(xué)習(xí)有所幫助,可以手機掃描二維碼進行捐贈
------分隔線----------------------------
------分隔線----------------------------
主站蜘蛛池模板:
81精品国产乱码久久久久久
|
欧美精品一级二级三级
|
高潮白浆女日韩av免费看
|
一区二区精品视频
|
日韩在线播放视频
|
色在线视频
|
亚洲第一二区
|
91久久国产综合久久蜜月精品
|
av无遮挡|
日本成人一区
|
粉嫩av亚洲一区二区图片
|
亚洲一级片免费
|
国产亚洲一区二区三区
|
亚洲午夜免费视频
|
国产福利视频在线观看
|
九九香蕉视频
|
国产成人在线电影
|
国产曰批免费观看久久久
|
91久久精品一区二区二区
|
国产精品自拍一区
|
精品久久久久久久久久
|
九九热视频在线
|
免费看男女www网站入口在线
|
黄色大片免费看
|
一区二区三区日韩欧美
|
久久久久久国产精品免费免费
|
操人视频网站
|
久久精品一区二区三区四区
|
国产精品久久久久久久久免费高清
|
国产精品久久久久9999鸭
|
欧美偷拍综合
|
国内精品一区二区三区视频
|
性天堂|
成年人网站免费在线
|
中文字幕精品久久久久
|
日韩激情一区
|
亚洲成人福利
|
蜜桃精品一区二区三区
|
国产一级一级国产
|
国内精品国产成人国产三级粉色
|
国产精品免费一区
|