国内最全IT社区平台 联系我们 | 收藏本站
华晨云阿里云优惠2
您当前位置:首页 > php开源 > 综合技术 > acm_icpc网络赛第六站:上海赛区(跪烂心已死)

acm_icpc网络赛第六站:上海赛区(跪烂心已死)

来源:程序员人生   发布时间:2014-10-11 08:00:01 阅读次数:3640次

最后一站了,很无奈的是还是没出线,最终3题结束,排名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
2 1 2
 

Sample Output
Case #1: 2 Case #2: 19
递推+大数
增加第n+1个 “M”时,交点最多有16n个,所以增加区域 16n+1个;
f(n+1)-f(n)=16*n+1;
f(1)=2;
解得
f(n)=n*(8*n-7)+1;
然后 直接上BigInteger 就行了 然后悲剧的是当时我不会java的输入优化结果出题人故意卡java。。最后队友敲的数组模拟过的
下面上java输入输出优化的代码 很简单~
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();//刷新缓冲区 (必须)
        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的最大公约数 还是BigInteger 由于一开始不知道BigInteger二进制的转换 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
生活不易,码农辛苦
如果您觉得本网站对您的学习有所帮助,可以手机扫描二维码进行捐赠
程序员人生
------分隔线----------------------------
分享到:
------分隔线----------------------------
关闭
程序员人生