codeforces 190A Vasya and the Bus

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

public class CF190A {

	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String[] nm = in.readLine().split(" ");
		int n = Integer.parseInt(nm[0]);
		int m = Integer.parseInt(nm[1]);
		if (n == 0 && m == 0) {
			System.out.println(0 + " " + 0);
			return;
		}
		if (n == 0) {
			System.out.println("Impossible");
			return;
		}
		if (m == 0) {
			System.out.println(n + " " + n);
			return;
		}
		int min = 0;
		if (n > m) {
			int tn = n;
			for (int i = 0; i < m; i++) {
				min += 1;
				tn -= 1;
			}
			min += tn;
		} else {
			min = m;
		}

		int max = n - 1 + m;
		System.out.println(min + " " + max);
	}
}
时间: 2024-08-30 05:03:07

codeforces 190A Vasya and the Bus的相关文章

[2016-04-09][codeforces][660][B][Seating On Bus]

时间:2016-04-09 23:29:47 星期六 题目编号:[2016-04-09][codeforces][660][B][Seating On Bus] 题目大意:按指定顺序入座,按指定顺序出座,问最后出座的顺序 分析:直接4个queue模拟一遍 #include<cstdio> #include<queue> using namespace std; queue<int> q[4]; int main(){ int n,m; scanf("%d%d&

CodeForces 577C Vasya and Petya&#39;s Game 数学

题意就是给你一个1到n的范围 你每次可以问这个数是否可以被某一个数整除 问你要猜多少数才能确定这个数…… 一开始一点思路也没有 后来查了一下才知道 每个数都可以分为几个质数的整数次幂相乘得到…… 1 #include<stdio.h> 2 #include<iostream> 3 #include<algorithm> 4 #include<math.h> 5 #include<string.h> 6 #include<string>

CodeForces - 837E - Vasya&#39;s Function | Educational Codeforces Round 26

/* CodeForces - 837E - Vasya's Function [ 数论 ] | Educational Codeforces Round 26 题意: f(a, 0) = 0; f(a, b) = 1 + f(a, b-gcd(a, b)); 求 f(a, b) , a,b <= 1e12 分析: b 每次减 gcd(a, b) 等价于 b/gcd(a,b) 每次减 1 减到什么时候呢,就是 b/gcd(a,b)-k 后 不与 a 互质 可先将 a 质因数分解,b能除就除,不能

Codeforces 837E Vasya&#39;s Function 数论 找规律

题意:定义F(a,0) = 0,F(a,b) = 1 + F(a,b - GCD(a,b).给定 x 和 y (<=1e12)求F(x,y). 题解:a=A*GCD(a,b) b=B*GCD(a,b),那么b-GCD(a,b) = (B-1)*GCD(a,b),如果此时A和B-1依然互质,那么GCD不变下一次还是要执行b-GCD(a,b).那么GCD什么时候才会变化呢?就是说找到一个最小的S,使得(B-S)%T=0其中T是a的任意一个因子.变形得到:B%T=S于是我们知道S=min(B%T).也

Codeforces 837E Vasya&#39;s Function - 数论

Vasya is studying number theory. He has denoted a function f(a, b) such that: f(a, 0) = 0; f(a, b) = 1 + f(a, b - gcd(a, b)), where gcd(a, b) is the greatest common divisor of a and b. Vasya has two numbers x and y, and he wants to calculate f(x, y).

Codeforces 837E. Vasya&#39;s Function

http://codeforces.com/problemset/problem/837/E 题意: f(a, 0) = 0; f(a, b) = 1 + f(a, b - gcd(a, b)) 输出f(a,b) a=A*gcd(a,b)    b=B*gcd(a,b) 一次递归后,变成了 f(A*gcd(a,b),(B-1)*gcd(a,b)) 若gcd(A,(B-1))=1,那么 这一层递归的gcd(a,b)仍等于上一层递归的gcd(a,b) 也就是说,b-gcd(a,b),有大量的时间减的

codeforces 493C Vasya and Basketball (枚举+模拟+思维)

C. Vasya and Basketball time limit per test 2 seconds memory limit per test 256 megabytes Vasya follows a basketball game and marks the distances from which each team makes a throw. He knows that each successful throw has value of either 2 or 3 point

CodeForces 493D Vasya and Chess 简单博弈

Vasya and Chess Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u CodeForces 493D Description Vasya decided to learn to play chess. Classic chess doesn't seem interesting to him, so he plays his own sort of chess. The quee

codeforces 493B.Vasya and Wrestling 解题报告

题目链接:http://codeforces.com/problemset/problem/493/B 题目意思:给出 n 个 techniques,每个 technique 的值为 ai. ai > 0 表示把这个分数给第一个wrestler,ai < 0,表示给第二个wrestler.约定 ai != 0. 如果两个人最终的得分不相等,分数多的那个人获胜. 如果两个人最终的得分相等,可以分两种情况讨论: (1)序列中至少有一位不相等,那么字典序大的那个获胜.例如第一个人:1, 4, 5,