小喵们很喜欢把自己装进容器里的(例如碗),但是要是碗的周长比喵的身长还短,它们就进不去了。
现在告诉你它们的身长,和碗的半径,请判断一下能否到碗里去。
输入有多组数据。
每组数据包含两个整数n (1≤n≤2^128) 和r (1≤r≤2^128),分别代表喵的身长和碗的半径。
圆周率使用3.14。
对应每一组数据,如果喵能装进碗里就输出“Yes”;否则输出“No”。
6 1 7 1 9876543210 1234567890
Yes No No
long double防止溢出。 #include<iostream> #include<vector> #include<string> #include<algorithm> #include<functional> #include <map> #include <set> #include <unordered_set> #include <unordered_map> #include <exception> using namespace std; int main(int argc, char** argv) { long double n,r; while (cin >> n >> r) { if (2 * r * 3.14 >= n) cout << "Yes" << endl; else cout << "No" << endl; } return 0; }
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (sc.hasNext()) { Double n = sc.nextDouble(); Double r = sc.nextDouble(); if(n < 2 * 3.14 * r) System.out.println("Yes"); else System.out.println("No"); } } }
#include <stdio.h> #include <stdlib.h> #define P 3.14 #define CIRCUMFERENCE(r) (2*(P)*(r)) int is_completion(const int height, const int radius) { int res = 0; res = ((CIRCUMFERENCE(radius) < height) ? (1 : 0)); return res; }
int main(int argc, char const *argv[]) { /* code */ int res; int height, radius; printf("please input the height of cat, and input the radius:"); scanf("%d,%d", &height, &radius); res = is_completion(&height, &radius);
if (res) { /* code */ printf("NO\n"); } else{ printf("YES\n"); } return 0; }
#include <iostream> #include <string> using namespace std; string times628(string & str) { string ret(str.length() + 3, 0); string str628 = "628"; int strL = str.length(); int retL = ret.length(); int c = 0; for (int k = 2; k >= 0; --k) for (int i = strL - 1, j = retL + k - 3; i >= 0; --i, --j) ret[j] += (str[i] - '0') * (str628[k] - '0'); for (int i = retL; i >= 0; --i) { ret[i] += c; c = ret[i] / 10; ret[i] = ret[i] % 10 + '0'; } int index = 0; while (ret[index] == '0') ++index; return string(ret.begin() + index, ret.end() - 2); } int compare(string & a, string & b) { if (a.length() != b.length()) return (a.length() > b.length() ? 1 : -1); else { for (int i = 0; i < a.length(); ++i) if (a[i] == b[i]) continue; else return (a[i] > b[i] ? 1 : -1); return 0; } } int main() { string n, r; while (cin >> n >> r) { r = times628(r); if (compare(n, r) == 1) cout << "No" << endl; else cout << "Yes" << endl; } return 0; }
import java.util.LinkedList; import java.util.Scanner; public class Main { //小猫咪钻罐子 public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while (scanner.hasNext()){ //猫 String s1 = scanner.next(); //罐子 String s2 = scanner.next(); LinkedList<Integer> list1 = new LinkedList<>(); LinkedList<Integer> list2 = new LinkedList<>(); for (int i = 0; i < s1.length(); i++) { list1.add(s1.charAt(i)-'0'); } for (int i = 0; i < s2.length(); i++) { list2.add(s2.charAt(i)-'0'); } int size = list2.size()-1;//对应最后一个元素得下标 for (int i = size; i >= 0; i--) { //将size下标得值*2 list2.set(i,list2.get(i)*2); } //再全部进数 for (int i = size; i >= 0 ; i--) { if(list2.get(i) >= 10){ //进位,将前面得值+1 if(i == 0){ //如果是头插就插入1 list2.addFirst(1); list2.set( 1 ,list2.get(1) % 10); }else { //如果不是头插就修改值 list2.set( i-1 ,list2.get(i-1)+1); //进位后将当前值%10 list2.set( i ,list2.get(i) % 10); } } } // System.out.println(list2); size = list2.size()-1;//重新更新下size的值 //Πd,此时d处理了,就差*Π了 //*314 LinkedList<Integer> list = new LinkedList<>(); int[]pai = {3,1,4}; int n1 = 0;//记录相加 int n2 = 0;//记录相乘 int z = 0;//一直记录倒数第二个位置 for (int i = 2; i >= 0 ; i--) { n1++; n2 = n1; for (int j = size; j >= 0 ; j--) { z = list.size()-n2; int p = list2.get(j); //说明此时没有对应的值 if(z == -1){ list.addFirst(p * pai[i]); z++; }else { int tmp = list.get(z); list.set(z,p * pai[i]+tmp); } if(list.get(z) >= 10){ //如果为0,说明需要头插 if(z == 0){ list.addFirst(list.get(z)/10); z++; }else { //如果不为0,就给前面的值加上进的位数 int tmp = list.get(z-1); list.set(z-1,list.get(z) / 10+tmp); } list.set(z,list.get(z) % 10); } n2++; } } // System.out.println(list); //做个标记,记录这个数组从哪里开始是小数 int len = list.size()-2; //从后往前数,去二位0 int i = 0; while (i < 2){ //获取后数两位 //如果是0就删除 if(list.get(list.size()-1) == 0){ list.pollLast(); } i++; } size = 0;//记录次数 //类似于 12 111 if(list1.size() > len){ System.out.println("No"); }else if(list1.size() < len){ System.out.println("Yes"); }else { //两个一样长时 while (list1.size() != 0 && list.size() !=0){ //如果猫的身长小于碗的周长 if(list1.peekFirst() < list.peekFirst()){ System.out.println("Yes"); break; }else if(list1.peekFirst() > list.peekFirst()){ System.out.println("No"); break; }else { list1.pollFirst(); list.pollFirst(); } size++; } if(list1.size() == 0 && (list.get(0)!=0 || list.get(1)!=0)) System.out.println("Yes"); } } } }
#include <iostream> #include<vector> #include<algorithm> using namespace std; void getcomp(string a, string b) { if (a.length() < b.length()) { cout << "Yes" << endl; } else if (a.length() == b.length()) { auto lt = a.begin(); auto lb = b.begin(); while (lt != a.end()) { if (*lt > *lb) { cout << "No" << endl; break; } if(*lt<*lb){ cout << "Yes" << endl; break; } lt++; lb++; if(lt==a.end()&&lb==b.end()){ cout<<"Yes"<<endl; } } } else cout << "No" << endl; } string getsum(string a, string b) { auto la = a.begin(); auto lb = b.begin(); string str; int adv = 0; while (la != a.end() && lb != b.end()) { int tmp = (*la - '0') + (*lb - '0') + adv; str += (tmp % 10 + '0'); adv = tmp / 10; la++; lb++; } while (la != a.end()) { int tmp = (*la - '0') + adv; str += (tmp % 10 + '0'); adv = tmp / 10; la++; } while (lb != b.end()) { int tmp = (*lb - '0') + adv; str += (tmp % 10 + '0'); adv = tmp / 10; lb++; } return str;//倒序 } void constr(string a, string b) { a += "00"; reverse(b.begin(), b.end());//小在前 int ar[3] = { 8, 2, 6 }; vector<string>str(3); for (int i = 0; i < 3; i++) { auto la = b.begin(); int adv = 0; while (la != b.end()) { int tmp = ar[i] * (*la - '0') + adv; str[i] += (tmp % 10 + '0'); adv = tmp / 10; la++;//小数在高位 倒序 } if (adv != 0) str[i] += (adv + '0'); //reverse(str[i].begin(), str[i].end()); int j = i; while (j) { str[i].insert(str[i].begin(), '0'); j--; } } string abs; abs = getsum(str[0], str[1]); abs = getsum(abs, str[2]); reverse(abs.begin(), abs.end()); getcomp(a, abs); } int main() { string st1, st2; while (cin >> st1 >> st2 ) { constr(st1, st2); } return 0; }
唯一要注意的地方是 getcomp这个比较函数
从高位到低位 只要有a[i]>b[i ]就是No;只要有a[i]< b[i]就是Yes; 两判断条件缺一不可
import java.math.BigDecimal; import java.util.Scanner; public class Test { public static void main(String[] args) { Scanner in = new Scanner(System.in); //方法1:使用double来做 //while(in.hasNext()){ double n = in.nextDouble();//double 范围 -1.7 E—308~1.7E-308 是1.7*10的308次方 double r = in.nextDouble(); if(n > (2*3.14*r)){ System.out.println("No"); }else{ System.out.println("Yes"); } }// //方法2:BigDecimal来做,BigDecimal可以用来算大数(任意精度的十进制数(浮点数)) while(in.hasNext()){ String n =in.next(); String r =in.next(); BigDecimal a =new BigDecimal(n);//a是身长 BigDecimal b = new BigDecimal(r);//b是半径 BigDecimal c = new BigDecimal(6.28);//3.14*2 b=b.multiply(c);//周长:b*c if(a.compareTo(b)>0){//若a>b 返回1 System.out.println("No"); }else{ System.out.println("Yes"); } } } }
import java.math.BigInteger; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while (scanner.hasNext()){ BigInteger[] integers = new BigInteger[2]; integers[0] = scanner.nextBigInteger();//喵的身长 integers[1] = scanner.nextBigInteger();//碗的半径 if ((integers[1].doubleValue() * 2 * 3.14) < integers[0].doubleValue()){ System.out.println("No"); }else { System.out.println("Yes"); } } } }
import java.util.*; import java.io.*; import java.math.BigDecimal; public class Main{ public static void main(String[] args){ Scanner scan = new Scanner(System.in); while(scan.hasNext()){ BigDecimal n = scan.nextBigDecimal(); BigDecimal r = scan.nextBigDecimal(); BigDecimal len = new BigDecimal("6.28").multiply(r); System.out.println(n.compareTo(len) == 1?"No":"Yes"); } } }
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); while (in.hasNext()) { double n = in.nextDouble(); double r = in.nextDouble(); if(n >= 2 * 3.14 * r){ System.out.println("No"); }else{ System.out.println("Yes"); } } } }
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while (scanner.hasNext()) { Double cat = scanner.nextDouble(); Double perimeter = scanner.nextDouble(); if(cat < 2 * 3.14 * perimeter){ System.out.println("Yes"); } else { System.out.println("No"); } } } }
import java.util.*; import java.math.*; public class Main{ public static void main(String[] args){ Scanner scanner = new Scanner(System.in); while(scanner.hasNext()){ String str1 = scanner.next(); String str2 = scanner.next(); BigDecimal bigInteger1 = new BigDecimal(str1); BigDecimal bigInteger2 = new BigDecimal(str2); BigDecimal bigInteger3 = new BigDecimal("3.14"); bigInteger2 = bigInteger2.multiply(bigInteger3.multiply(new BigDecimal("2"))); int num = bigInteger1.compareTo(bigInteger2); if(num == -1){ System.out.println("Yes"); }else if(num == 0){ System.out.println("Yes"); }else if(num == 1){ System.out.println("No"); } } } }