NYOJ_语言入门

package org.acm.newhand;

/*http://acm.nyist.net/JudgeOnline/problem.php?pid=4*/

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;

public class NYOJ_4 {

	private static char chs[];

	public static void main(String[] args) {

		Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));

		int T = Integer.parseInt(sc.nextLine());
		while (T-- > 0) {
			chs = sc.nextLine().toCharArray();
			Arrays.sort(chs);//快排
			
			for (int i = 0; i < chs.length; i++) 
				System.out.print(chs[i]+" ");
			System.out.println();
		}sc.close();
	}
}
package org.acm.newhand;

/*http://acm.nyist.net/JudgeOnline/problem.php?pid=22*/

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class NYOJ_22 {

	private static int n, sum;
	private static boolean prime[] = new boolean[1001];

	// 线性素数筛选法
	static {
		prime[0] = true;
		prime[1] = true;
		for (int i = 2; i < 40; i++) {
			if (!prime[i]) {
				for (int j = i * i; j < 1001; j += i)
					prime[j] = true;
			}
		}
	}

	public static void main(String[] args) {

		Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));

		int t = sc.nextInt();
		while (t-- > 0) {

			n = sc.nextInt();
			sum = 0;
			int num;
			// 把n之前的素数相加
			for (int i = 0; i < n; i++) {
				num = sc.nextInt();
				if (!prime[num])
					sum += num;
			}
			System.out.println(sum);
		}
		sc.close();
	}
}
package org.acm.newhand;

/*http://acm.nyist.net/JudgeOnline/problem.php?pid=24*/

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class NYOJ_24 {

	private static int n, min, max;
	private static boolean prime[] = new boolean[1000100];
	static {
		prime[0] = true;
		prime[1] = true;
		for (int i = 2; i < 1050; i++) {
			if (!prime[i]) {
				for (int j = i * i; j < 1000100; j += i)
					prime[j] = true;
			}
		}
	}

	public static void main(String[] args) {

		Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));

		int t = sc.nextInt();
		while (t-- > 0) {

			n = sc.nextInt();
			if (!prime[n])
				System.out.println(n + " " + 0);
			else if (n == 0 || n == 1)
				System.out.println(2 + " " + (2 - n));
			else {

				// 获取到一个比n大的素数
				max = n + 1;
				while (prime[max])
					max += 1;

				// 获取到一个比n小的素数
				min = n - 1;
				while (prime[min])
					min -= 1;

				// 比谁近
				int a = max - n, b = n - min;
				if (a >= b)
					System.out.println(min + " " + b);
				else
					System.out.println(max + " " + a);
			}
		}
		sc.close();
	}
}
package org.acm.newhand;

/*http://acm.nyist.net/JudgeOnline/problem.php?pid=33*/
//模拟题

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class NYOJ_33 {

	private static int n, m, x, y, z, max, tmpn;
	private static int arr[][] = new int[101][101];

	public static void main(String[] args) {

		Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));

		while (sc.hasNext()) {

			n = sc.nextInt();
			tmpn = n;
			max = n * n;
			m = 1;
			x = 1;
			y = n;
			z = 1;
			while (m <= max) {

				//右边的从上往下
				while (m <= max && x <= n) {
					arr[x++][y] = m++;
				}
				x--;
				y--;

				//下边的从右往左
				while (m <= max && y >= z)
					arr[x][y--] = m++;
				x--;
				y++;

				//左边的从下往上
				while (m <= max && x >= y)
					arr[x--][y] = m++;
				x++;
				y++;

				//上边的从左往右
				while (m <= max && y < n)
					arr[x][y++] = m++;
				x++;
				y--;
				n--;
				z++;
			}

			for (int i = 1; i <= tmpn; i++) {
				for (int j = 1; j <= tmpn; j++)
					System.out.print(arr[i][j] + " ");
				System.out.println();
			}
		}
		sc.close();
	}
}
package org.acm.newhand;

/*http://acm.nyist.net/JudgeOnline/problem.php?pid=34*/

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class NYOJ_34 {

	private static int a, b, c;

	public static void main(String[] args) {

		Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));

		while (sc.hasNext()) {
			a = sc.nextInt();
			b = sc.nextInt();
			c = sc.nextInt();

			int i;
			for (i = 10; i < 101; i++) {
				if (i % 3 == a && i % 5 == b && i % 7 == c) {
					System.out.println(i);
					break;
				}
			}
			if (i == 101)
				System.out.println("No answer");
		}
		sc.close();
	}
}
package org.acm.newhand;

/*http://acm.nyist.net/JudgeOnline/problem.php?pid=56*/

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class NYOJ_56 {

	private static int n, m, count_m;

	public static void main(String[] args) {

		Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));

		int t = sc.nextInt();
		while (t-- > 0) {

			n = sc.nextInt();
			m = sc.nextInt();
			count_m = 0;
			// n / m 表示 在 1 到 n 中所有的数中有n/m个能够整除b,直到n/m==0
			while (n / m > 0) {
				n /= m;
				count_m += n;
			}
			System.out.println(count_m);
		}
		sc.close();
	}
}
package org.acm.newhand;

/*http://acm.nyist.net/JudgeOnline/problem.php?pid=60*/

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class NYOJ_60 {

	// 学生类
	public static class Student {
		public String name, stulead, weststu;
		public int tg, cg, thesis;
		public int sum;

		public Student() {}

		public Student(String name, int tg, int cg, String stulead, String weststu, int thesis) {
			this.name = name;
			this.tg = tg;
			this.cg = cg;
			this.stulead = stulead;
			this.weststu = weststu;
			this.thesis = thesis;
		}
	}

	private static Student[] stus = new Student[101];// 学生数组
	private static int x;

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int T = Integer.parseInt(br.readLine());
		while (T-- > 0) {

			Arrays.fill(stus, new Student());

			x = Integer.parseInt(br.readLine());
			String studata[];
			for (int i = 1; i <= x; i++) {
				studata = br.readLine().split(" ");
				stus[i] = new Student(studata[0], Integer.parseInt(studata[1]), Integer.parseInt(studata[2]), studata[3],
						studata[4], Integer.parseInt(studata[5]));
			}
			compare(stus);
		}
	}

	// 评比奖学金
	private static void compare(Student stus[]) {

		int max = 0, sum = 0;
		String who_getmaxmoney_name = "";
		for (int i = 1; i <= x; i++) {
			// 院士奖学金
			if (stus[i].tg > 80 && stus[i].thesis >= 1)
				stus[i].sum += 8000;
			// 五四奖学金
			if (stus[i].tg > 85 && stus[i].cg > 80)
				stus[i].sum += 4000;
			// 成绩优秀奖
			if (stus[i].tg > 90)
				stus[i].sum += 2000;
			// 西部奖学金
			if (stus[i].tg > 85 && stus[i].weststu.equals("Y"))
				stus[i].sum += 1000;
			// 班级贡献奖
			if (stus[i].cg > 80 && stus[i].stulead.equals("Y"))
				stus[i].sum += 850;

			// 找出拿钱最多的童鞋
			if (stus[i].sum > max) {
				max = stus[i].sum;
				who_getmaxmoney_name = stus[i].name;
			}
			sum += stus[i].sum;
		}
		System.out.println(who_getmaxmoney_name);
		System.out.println(max);
		System.out.println(sum);
	}
}
package org.acm.newhand;

/*http://acm.nyist.net/JudgeOnline/problem.php?pid=65*/

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class NYOJ_65 {

	public static void main(String[] args) {

		Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));

		int t = sc.nextInt();
		while (t-- > 0) {
			int n = sc.nextInt();

			int pro, sum = 0;
			for (int i = 1; i <= n; i++) {
				pro = 1;
				for (int j = 1; j <= i; j += 2) {// i!!
					pro *= j;
				}
				sum += pro;
			}
			System.out.println(sum);
		}
		sc.close();
	}
}
package org.acm.newhand;

/*http://acm.nyist.net/JudgeOnline/problem.php?pid=74*/

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class NYOJ_74 {

	private static int n, m;

	public static void main(String[] args) {

		Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));

		while (true) {

			n = sc.nextInt();
			m = sc.nextInt();
			if (n == 0 && m == 0)
				break;

			// 把两个数都分拆
			int a = n / 100;
			int b = n / 10 % 10;
			int c = n % 100 % 10;

			int d = m / 100;
			int e = m / 10 % 10;
			int f = m % 100 % 10;

			int count = 0;
			int yuo = 0, yut = 0;
			// 个位
			if (c + f > 9) {
				count++;
				yuo = 1;
			}

			// 十位
			if (b + e + yuo > 9) {
				count++;
				yut = 1;
			}

			// 百位
			if (a + d + yut > 9)
				count++;
			System.out.println(count);
		}
		sc.close();
	}
}
package org.acm.newhand;

/*http://acm.nyist.net/JudgeOnline/problem.php?pid=97*/

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class NYOJ_97 {

	private static int M, X, Y, Z;

	public static void main(String[] args) {

		Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));

		int n = sc.nextInt();
		while (n-- > 0) {

			M = sc.nextInt();
			X = sc.nextInt();
			Y = sc.nextInt();
			Z = sc.nextInt();

			// (M * X)/(Y-X)哥哥追上弟弟用的时间
			System.out.println(String.format("%.2f", Z * ((float) (M * X) / (Y - X))));
		}
		sc.close();
	}
}
package org.acm.newhand;

/*http://acm.nyist.net/JudgeOnline/problem.php?pid=100*/

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class NYOJ_100 {

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int t = Integer.parseInt(br.readLine());
		String n;
		int count;
		while (t-- > 0) {
			n = Integer.toBinaryString(Integer.parseInt(br.readLine()));
			count = 0;
			for (int i = 0; i < n.length(); i++) {
				switch (n.charAt(i)) {
				case '1':
					count += 1;
					break;
				default:
					break;
				}
			}
			System.out.println(count);
		}
	}
}
package org.acm.newhand;

/*http://acm.nyist.net/JudgeOnline/problem.php?pid=111*/

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class NYOJ_111 {

	private static int a, b, c, d, x, y, p, t;
	private static String n1[], n2[], num[];

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String str = null;
		while ((str = br.readLine()) != null) {

			if (str.contains("+"))
				num = str.split("\\+");
			else
				num = str.split("\\-");

			n1 = num[0].split("\\/");
			n2 = num[1].split("\\/");
			a = Integer.parseInt(n1[0]);
			b = Integer.parseInt(n1[1]);
			c = Integer.parseInt(n2[0]);
			d = Integer.parseInt(n2[1]);

			if (str.contains("+")) {
				x = a * d + b * c;
				y = b * d;
			} else {
				x = a * d - b * c;
				y = b * d;
			}
			p = x;
			t = y;

			// 约分
			if (x < y) {
				x = x ^ y;
				y = x ^ y;
				x = x ^ y;
			}
			while (y != 0) {
				x = x % y;
				x = x ^ y;
				y = x ^ y;
				x = x ^ y;
			}

			// 加法,x是公约数
			if (str.contains("+")) {
				if (p / x == 0)// 分子是0
					System.out.println(0);
				else if (p / x == t / x)
					System.out.println(p / x);
				else if (t / x == 1)// 分母是1
					System.out.println(p / x);
				else
					System.out.println(p / x + "/" + t / x);
			} else {

				if (p / x > 0 && t / x < 0)
					System.out.println(-1 * p / x + "/" + (-1 * t / x));
				else if (p / x == t / x)
					System.out.println(p / x);
				else if (t / x == 1)
					System.out.println(p / x);
				else if (p / x == 0)
					System.out.println(0);
				else
					System.out.println(p / x + "/" + t / x);
			}
		}
	}
}
package org.acm.newhand;

/*http://acm.nyist.net/JudgeOnline/problem.php?pid=122*/
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class NYOJ_122 {

	private static int n, sum;

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int t = Integer.parseInt(br.readLine());
		int c = 1;
		while (t-- > 0) {
			n = Integer.parseInt(br.readLine());
			sum = 0;
			for (int i = 1; i <= n; i++) {
				for (int j = 1; j <= i + 1; j++) {
					sum += i * j;
				}
			}
			System.out.println(c++ + " " + n + " " + sum);

		}
	}
}
package org.acm.newhand;

/*http://acm.nyist.net/JudgeOnline/problem.php?pid=125*/

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class NYOJ_125 {

	private static int n, step, second;// step是梦境的层数,second是现实过了多少秒
	private static String control[];
	private static int SPEED_VALUE = 20;// 第n层时间速度是n-1层的20倍

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int t = Integer.parseInt(br.readLine());
		while (t-- > 0) {

			n = Integer.parseInt(br.readLine());
			step = 0;// 一开始在0层,表示现实
			second = 0;
			for (int i = 1; i <= n; i++) {
				control = br.readLine().split(" ");
				if (control[0].equals("IN"))
					step++;
				else if (control[0].equals("OUT"))
					step--;
				else {
					int times = (int) Math.pow(SPEED_VALUE, step);// 该梦境的时间速度是显示的几倍
					int mins = Integer.parseInt(control[1]) / times;// 该梦境在现实中是几分钟
					double over = Double.parseDouble(control[1]) % times / times;// 余数
					second += mins * 60;// 将梦境里的时间转换成显示的秒
					second += over * 60;
				}
			}
			System.out.println(second);
		}
	}
}
package org.acm.newhand;

/*http://acm.nyist.net/JudgeOnline/problem.php?pid=168*/

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class NYOJ_168 {

	private static int t, n, a, b, c, max;
	private static String data[];
	private static int arr[] = new int[200];

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		t = Integer.parseInt(br.readLine());
		while (t-- > 0) {
			n = Integer.parseInt(br.readLine());
			max = 0;
			Arrays.fill(arr, 0);
			for (int i = 1; i <= n; i++) {
				data = br.readLine().split(" ");
				a = Integer.parseInt(data[0]);
				b = Integer.parseInt(data[1]);
				c = Integer.parseInt(data[2]);

				// 从第b天到b+c天又都a个房子被住
				for (int j = b; j < b + c; j++) {
					// 叠加订单,如果第j天还有人住arr[j]间房子,那么此时就得增加a间房子
					arr[j] += a;
					if (max < arr[j]) {
						max = arr[j];
					}
				}
			}
			System.out.println(max);
		}
	}
}
package org.acm.newhand;

/*http://acm.nyist.net/JudgeOnline/problem.php?pid=199*/

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class NYOJ_199 {

	private static int L, D, R;
	private static double len;
	private static String data[];

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int t = Integer.parseInt(br.readLine());
		while (t-- > 0) {

			data = br.readLine().split(" ");
			L = Integer.parseInt(data[0]);
			D = Integer.parseInt(data[1]);
			R = Integer.parseInt(data[2]);

			if ((R << 1) <= D)
				System.out.println("impossible");
			else {
				// 求出一个圆可以覆盖多长的长,宽和圆的直径用勾股定理求覆盖的长度
				len = Math.sqrt((R << 1) * (R << 1) - (D * D));
				System.out.println((int) Math.ceil(L / len));
			}
		}
	}
}
package org.acm.newhand;

/*http://acm.nyist.net/JudgeOnline/problem.php?pid=244*/

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class NYOJ_244 {

	private static String mode[] = { "0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011",
			"1100", "1101", "1110", "1111" };

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());
		String data[], datas;
		while (n-- > 0) {
			datas = br.readLine();
			if (datas.contains("+"))
				data = datas.split("\\+");
			else
				data = datas.split("\\-");

			// 获取到两个相加或相减的数,十六进制转换成2进制
			String a = "", b = "";
			for (int i = 0; i < data[0].length(); i++) {
				if (data[0].charAt(i) <= '9')
					a += mode[data[0].charAt(i) - '0'];
				else
					a += mode[data[0].charAt(i) - 87];
			}

			for (int i = 0; i < data[1].length(); i++) {
				if (data[1].charAt(i) <= '9')
					b += mode[data[1].charAt(i) - '0'];
				else
					b += mode[data[1].charAt(i) - 87];
			}

			int result = 0;
			// 转成2进制转换成10进制,并且计算结果
			if (datas.contains("+"))
				result = Integer.parseInt(a, 2) + Integer.parseInt(b, 2);
			else
				result = Integer.parseInt(a, 2) - Integer.parseInt(b, 2);
			// 结果转换成8进制
			System.out.println(Integer.toOctalString(result));
		}
	}
}
package org.acm.newhand;

/*http://acm.nyist.net/JudgeOnline/problem.php?pid=263*/

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;

public class NYOJ_263 {

	private static int maxlen, minwid, tempencode, a, b, c;

	public static void main(String[] args) throws IOException {

		Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));

		int t = sc.nextInt();
		int n;
		while (t-- > 0) {
			n = sc.nextInt();
			maxlen = -1;
			minwid = Integer.MAX_VALUE;
			tempencode = 0;
			for (int i = 0; i < n; i++) {
				a = sc.nextInt();
				b = sc.nextInt();
				c = sc.nextInt();
				// 比长细
				if (a > maxlen || b < minwid) {
					maxlen = a;
					minwid = b;
					tempencode = c;
				} else if (a == maxlen || b == minwid) {
					// 长细一样,比编号
					if (a == maxlen && b == minwid && c > tempencode) {
						tempencode = c;
						// 长一样,俾细
					} else if (a == maxlen && b < minwid) {
						maxlen = a;
						minwid = b;
						tempencode = c;
					} else if (a > maxlen && b == minwid) {
						maxlen = a;
						minwid = b;
						tempencode = c;
					}
				}
			}
			System.out.println(tempencode);
		}
		sc.close();
	}
}
package org.acm.newhand;

/*http://acm.nyist.net/JudgeOnline/problem.php?pid=811*/

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class NYOJ_811 {

	private static int arr[] = new int[10000];
	private static ArrayList<Integer> queue = new ArrayList<Integer>();

	public static void main(String[] args) {

		Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));

		while (sc.hasNext()) {
			queue.clear();
			int n = sc.nextInt();
			for (int i = 0; i < n; i++)
				arr[i] = sc.nextInt();

			for (int i = 0; i < n; i += 3) {
				// 奇数组取最大
				queue.add(max(arr[i], arr[i + 1], arr[i + 2]));
				i += 3;
				if (i >= n)
					break;
				// 偶数组取最小
				queue.add(min(arr[i], arr[i + 1], arr[i + 2]));
			}
			Collections.sort(queue);//排序
			System.out.println(queue.get(n / 3 - 1));
		}
		sc.close();
	}

	private static int max(int a, int b, int c) {
		return Math.max(Math.max(a, b), c);
	}

	private static int min(int a, int b, int c) {
		return Math.min(Math.min(a, b), c);
	}
}
package org.acm.newhand;

/*http://acm.nyist.net/JudgeOnline/problem.php?pid=975*/

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class NYOJ_975 {

	private static int n, m;
	private static int arr[][] = new int[1000001][2];

	// 先把数据保存起来,往后递推
	static {
		for (int i = 125; i < 1000000; i++) {
			String str = String.valueOf(i);
			if (str.contains("521"))
				arr[i][0] = arr[i - 1][0] + 1;
			else
				arr[i][0] = arr[i - 1][0];

			if (str.contains("5") && str.contains("2") && str.contains("1"))
				arr[i][1] = arr[i - 1][1] + 1;
			else
				arr[i][1] = arr[i - 1][1];
		}
	}

	public static void main(String[] args) {

		Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));

		int count = 1;
		while (sc.hasNext()) {
			n = sc.nextInt();
			m = sc.nextInt();
			System.out.println("Case " + count++ + ":" + (arr[m][1] - arr[n - 1][1]) + " " + (arr[m][0] - arr[n - 1][0]));
		}
		sc.close();
	}
}






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值