import java.util.Scanner;
public class Q1 {
static double price, discount, sum = 0;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
sc.next();
price = Double.parseDouble(sc.next());
String str = sc.next();
if ("半价".equals(str))
discount = 0.5;
else if (str.length() == 2)
discount = 0.1 * (str.charAt(0) - '0');
else
discount = 0.01 * Integer.parseInt(str.substring(0, 2));
sum += price * discount;
}
System.out.println(sum);
}
}
答案:5200
public class Q2 {
static int[] a = new int[15];
static boolean[] book = new boolean[15];
static int ans = 0;
static void dfs(int step) {
if (step == 10) {
judge();
return;
}
for (int i = 1; i < 10; i++) {
if (!book[i]) {
book[i] = true;
a[step] = i;
dfs(step + 1);
book[i] = false;
}
}
}
static void judge() {
int sum = sum(1, 4);
if (sum != sum(4, 7)) return;
if (sum != sum(7, 9) + a[1]) return;
ans++;
}
static int sum(int s, int e) {
int res = 0;
for (int i = s; i <= e; i++)
res += a[i];
return res;
}
public static void main(String[] args) {
dfs(1);
System.out.println(ans / 3 / 2);
}
}
答案:144
import java.util.Scanner;
public class Q3 {
static double[][] a = new double[40][40];
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
for (int i = 1; i < 30; i++) {
for (int j = 1; j <= i; j++) {
a[i][j] = sc.nextDouble();
}
}
for (int i = 1; i < 30; i++) {
for (int j = 1; j <= i; j++) {
a[i + 1][j] += a[i][j] / 2;
a[i + 1][j + 1] += a[i][j] / 2;
}
}
double min = Double.MAX_VALUE, max = 0;
for (int i = 1; i <= 30; i++) {
min = Math.min(min, a[30][i]);
max = Math.max(max, a[30][i]);
}
// 2086458231 / min = x / max
System.out.println((long)(2086458231 * max / min));
}
}
答案:72665192664
public class Q5
{
static int len(int x){
if(x<10) return 1;
return len(x/10)+1;
}
// 取x的第k位数字
static int f(int x, int k){
if(len(x)-k==0) return x%10;
return f(x / 10, k); //填空
}
public static void main(String[] args)
{
int x = 23513;
//System.out.println(len(x));
System.out.println(f(x,3));
}
}
public class Q6
{
static int f(String s1, String s2)
{
char[] c1 = s1.toCharArray();
char[] c2 = s2.toCharArray();
int[][] a = new int[c1.length+1][c2.length+1];
int max = 0;
for(int i=1; i<a.length; i++){
for(int j=1; j<a[i].length; j++){
if(c1[i-1]==c2[j-1]) {
a[i][j] = a[i - 1][j - 1] + 1; //填空
if(a[i][j] > max) max = a[i][j];
}
}
}
return max;
}
public static void main(String[] args){
int n = f("abcdkkk", "baabcdadabc");
System.out.println(n);
}
}
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;
public class Q7 {
static int[] days = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
// a[0] -> 年, a[1] -> 月, a[2] -> 日
static int[] a = new int[3];
static List<String> list = new ArrayList<>();
static Set<String> set = new HashSet<>();
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String str = sc.next();
String[] strs = str.split("\\/");
set_y_m_d(strs);
judge();
set_m_d_y(strs);
judge();
set_d_m_y(strs);
judge();
Collections.sort(list);
for (String t : list)
System.out.println(t);
}
static void judge() {
a[0] += 1900;
if (check() && !set.contains(_2time())) {
list.add(_2time());
set.add(_2time());
}
a[0] += 100;
if (check() && !set.contains(_2time())) {
list.add(_2time());
set.add(_2time());
}
}
static boolean check() {
if (a[0] < 1960 || a[0] > 2059) return false;
if (a[1] < 1 || a[1] > 12) return false;
if (a[1] == 2 && a[2] == 29 && isRun(a[0])) return true;
return a[2] <= days[a[1]] && a[2] > 0;
}
static boolean isRun(int y) {
return (y % 4 == 0 && y % 100 != 0) || (y % 400 == 0);
}
static int str2int(String str) {
return (str.charAt(0) - '0') * 10 + (str.charAt(1) - '0');
}
static void set_y_m_d(String[] strs) {
a[0] = str2int(strs[0]);
a[1] = str2int(strs[1]);
a[2] = str2int(strs[2]);
}
static void set_m_d_y(String[] strs) {
a[1] = str2int(strs[0]);
a[2] = str2int(strs[1]);
a[0] = str2int(strs[2]);
}
static void set_d_m_y(String[] strs) {
a[2] = str2int(strs[0]);
a[1] = str2int(strs[1]);
a[0] = str2int(strs[2]);
}
static String _2time() {
String res = "";
res += a[0] + "-";
res += (a[1] >= 10 ? a[1] : "0" + a[1]) + "-";
res += a[2] >= 10 ? a[2] : "0" + a[2];
return res;
}
}
import java.util.Scanner;
public class Q8 {
static int MAX = 10000;
static int n;
static int[] a = new int[100];
static boolean[] dp = new boolean[MAX];
static int min = 105, pre = 0, ans = 0;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
for (int i = 0; i < n; i++) {
a[i] = sc.nextInt();
min = Math.min(min, a[i]);
}
dp[0] = true;
for (int i = 1; i < MAX; i++) {
if (i == MAX - 1) {
System.out.println("INF");
return;
}
for (int j = 0; j < n; j++) {
if (i - a[j] >= 0) {
dp[i] |= dp[i - a[j]];
}
}
if (!dp[i]) pre = i;
if (i - pre >= min) break;
}
for (int i = 1; i <= pre; i++) {
if (!dp[i]) ans++;
}
System.out.println(ans);
}
}
public class Q9 {
static int MAX_N = 100005;
static int n, k;
static int[][] a = new int[MAX_N][2];
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
k = sc.nextInt();
for (int i = 0; i < n; i++) {
a[i][0] = sc.nextInt();
a[i][1] = sc.nextInt();
}
int lo = 1, hi = 100000;
while (lo <= hi) {
int mid = (lo + hi) >>> 1;
int cnt = 0;
for (int i = 0; i < n; i++) {
cnt += (a[i][0] / mid) * (a[i][1] / mid);
}
if (cnt >= k)
lo = mid + 1;
else
hi = mid - 1;
}
System.out.println(lo - 1);
}
}