vj补题(CUIT新生娱乐赛)
A - 转二进制2
请你把一个整数n转化为二进制并从高位到低位输出。
Input
一行一个整数n,保证1<=n<=10^9。
Output
从高位到低位输出一个二进制数,表示n的二进制形式,每位之间不需要空格。
Sample Input
11
Sample Output
1011
Code:
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,a[100],i=0,j;
cin>>n;
while(n)
{
a[i]=n%2;
n=n/2;
i++;
}
for(j=i-1;j>=0;j--)
cout<<a[j];
return 0;
}
B - How many days?
8600的手机每天消费1元,每消费K元就可以获赠1元,一开始8600有M元,问最多可以用多少天?
Input
输入包括多个测试实例.每个测试实例包括2个整数M, k,(2 <= k <= M <= 1000).M = 0, k = 0代表输入结束.
Output
对于每个测试实例输出一个整数,表示M元可以用的天数。
Sample Input
2 2
4 3
0 0
Sample Output
3
5
Code:
#include <iostream>
using namespace std;
int main()
{
int m, k;
while(cin >> m >> k && (m || k)) {
int days = 0, cnt = 0;
while(m) {
m--, days++, cnt++;
if(cnt == k)
m++, cnt = 0;
}
cout << days << endl;
}
return 0;
}
C - Yet Another Dividing into Teams
rymm想要组建属于自己的篮球队。于是他就招到了n个球员。每个球员都有一个神秘力量ai。(注意:所有队员的神秘力量都不相同!!!)
作为篮球队的主教练,rymm想要他的球员分组训练。但是他发现如果一个组内任意两个球员的神秘力量相差过少(小于等于1),那么这两个球员就会打架,所以不能把他们分到同一组。由于每多分一个组,rymm就要多花伙食费(毕竟一个组要一起吃饭嘛)。
于是,rymm想问问你他最少可以分几组。
输入
第一行一个整数q(1≤q≤100),代表q组询问,对于每组询问:
第一行一个整数 n (1≤n≤100) ,代表rymm的球员数
第二行n个整数a1,a2,…,an (1≤ai≤100, 所有ai不相同),代表第i个球员的神秘力量。
输出
对于每个询问,输出一个整数,代表rymm最少可以分的组数
样例输入
4
4
2 10 1 20
2
3 6
5
2 3 4 99 100
1
42
样例输出
2
1
2
1
Note
在示例的第一个查询中,有n = 4个球员的神秘力量a = [2,10,1,20]。 这里只有一个限制:第一和第三名球员不能在同一组中(因为| a1-a3 | = | 2-1| = 1)。 可以将他们分为2组:例如,第一组的球员1、2和4,第二组的球员3。
在示例的第二个查询中,有n = 2个球员的神秘力量a = [3,6]。 可以只组成一个包含两个球员的团队。
Code:
tips:所有的a[i]不相同,不需要判断a[i]-a[i-1]==0
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
void maopao(int a[], int n)
{
int i,j,temp;
for (j=0;j<n-1;j++)
{
for (i=0;i<n-1-j;i++)
{
if(a[i]>a[i+1])
{
temp=a[i];
a[i]=a[i+1];
a[i+1]=temp;
}
}
}
}
int main()
{
int q,n,a[100]={0};
cin>>q;
for(int i = 0;i < q;i++){
cin>>n;
for(int j = 0;j < n;j++){
cin>>a[j];
}
maopao(a,n);
bool q = 0;
for(int i = 1;i < n;i++)
if(a[i]-a[i-1]==1)q = 1;
if(q == 1)printf("2\n");
else printf("1\n");
}
return 0;
}
D - A Funny Game
Alice and Bob decide to play a funny game. At the beginning of the game they pick n(1 <= n <= 106) coins in a circle, as Figure 1 shows. A move consists in removing one or two adjacent coins, leaving all other coins untouched. At least one coin must be removed. Players alternate moves with Alice starting. The player that removes the last coin wins. (The last player to move wins. If you can't move, you lose.)
Figure 1

Note: For n > 3, we use c1, c2, ..., cn to denote the coins clockwise and if Alice remove c2, then c1 and c3 are NOT adjacent! (Because there is an empty place between c1 and c3.)
Suppose that both Alice and Bob do their best in the game.
You are to write a program to determine who will finally win the game.
Input
There are several test cases. Each test case has only one line, which contains a positive integer n (1 <= n <= 106). There are no blank lines between cases. A line with a single 0 terminates the input.
Output
For each test case, if Alice win the game,output "Alice", otherwise output "Bob".
Sample Input
1
2
3
0
Sample Output
Alice
Alice
Bob
E - Pizza, Pizza, Pizza!!!
Katie, Kuro and Shiro are best friends. They have known each other since kindergarten. That's why they often share everything with each other and work together on some very hard problems.
Today is Shiro's birthday. She really loves pizza so she wants to invite her friends to the pizza restaurant near her house to celebrate her birthday, including her best friends Katie and Kuro.
She has ordered a very big round pizza, in order to serve her many friends. Exactly n of Shiro's friends are here. That's why she has to divide the pizza into n+1 slices (Shiro also needs to eat). She wants the slices to be exactly the same size and shape. If not, some of her friends will get mad and go home early, and the party will be over.
Shiro is now hungry. She wants to cut the pizza with minimum of straight cuts. A cut is a straight segment, it might have ends inside or outside the pizza. But she is too lazy to pick up the calculator.
As usual, she will ask Katie and Kuro for help. But they haven't come yet. Could you help Shiro with this problem?
Input
A single line contains one non-negative integer n (0≤n≤1018) — the number of Shiro's friends. The circular pizza has to be sliced into n+1 pieces.
Output
A single integer — the number of straight cuts Shiro needs.
Examples
Input
3
Output
2
Input
4
Output
5
Note
To cut the round pizza into quarters one has to make two cuts through the center with angle 90∘ between them.
To cut the round pizza into five equal parts one has to make five cuts.
Code:
tip:n == 0,输出0 n<=1e18 用long long
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
long long n;
int main()
{
cin >> n;
if(n == 0)printf("0\n");
else if((n+1)%2==0)printf("%d\n",(n+1)/2);
else printf("%d\n",n+1);
return 0;
}

浙公网安备 33010602011771号