A. Abiyoyo(水题)
题意:
输出k个Abiyoyo, Abiyoyo.,然后输出两个 Abiyoyo, yo yoyo yo yoyo.
#include <bits/stdc++.h>
using namespace std;
int main(){
int t;
cin >> t;
while(t--){
int k;
cin >> k;
for(int i = 1; i <= k; i++){
cout << "Abiyoyo, Abiyoyo." << endl;
}
cout << "Abiyoyo, yo yoyo yo yoyo." << endl;
cout << "Abiyoyo, yo yoyo yo yoyo." << endl;
}
return 0;
}
B.The Chosen One
题意:
给个n,每次删去在奇数位上的数,求最后剩下的数是几
举例 n = 8;
1 , 2 , 3, 4, 5, 6, 7, 8
2, 4, 6, 8
4, 8
8
题解:
(考虑的话,就是能够整除2 最多次数的数)
先模拟打表,然后会发现答案就是离n最近的2的指数
import java.math.BigInteger;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
BigInteger n;
Scanner scanner = new Scanner(System.in);
int t = scanner.nextInt();
while(t != 0) {
n = scanner.nextBigInteger();
BigInteger ans = new BigInteger("2");
BigInteger k = new BigInteger("2");
while(ans.compareTo(n) == -1 || ans.compareTo(n) == 0) {
ans = ans.multiply(k);
}
System.out.println(ans.divide(new BigInteger("2")));
t--;
}
scanner.close();
}
}