Codeforces Round #414

B. Cutting Carrot

题目地址:http://codeforces.com/contest/794/problem/B

思路:三角函数的简单应用,三角函数里面的参数是弧度制

AC代码:

import java.text.DecimalFormat;
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		
		Scanner in = new Scanner(System.in);
		while (in.hasNextInt()) {
			long n = in.nextLong();
			long h = in.nextLong();
			for (int i=1; i<n; i++) {
				double x = Math.sqrt(h * h * i * 1.0 / n);
				DecimalFormat df = new DecimalFormat("0.000000000000");
				System.out.print(df.format(x) + " ");
			}
			System.out.println();
		}
	}

}

C. Naming Company

题目地址:http://codeforces.com/contest/794/problem/C

思路:

错误代码:

import java.util.Arrays;
import java.util.Scanner;

public class Main {
	
	static char[] first = new char[300010];
	static char[] second = new char[300010];
	
	public static void main(String[] args) {
		
		Scanner in = new Scanner(System.in);
		while (in.hasNext()) {
			first = in.next().toCharArray();
			second = in.next().toCharArray();
			//对0到first.length的数组进行排序,包括0不包括first.length
			Arrays.sort(first,0,first.length);
			Arrays.sort(second,0,second.length);
			String str = "";
			int len = first.length;
			int i;
			for (i=0; i<len/2; i++) {
				str += first[i];
				str += second[len-1-i];
			}
			if ((len & 1) == 1)
				str += first[i];
			System.out.println(str);
		}
	}

}

我这个思路是Oleg每次在剩余位置的最左边放入他目前最小的,而lgor每次在剩余位置的最右边放入最大的

给一个例子

cbxz
aaaa

正确答案是

abac

而我的是

baca

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值