问题 A: ABC Swap
时间限制: 1 Sec 内存限制: 128 MB
题目描述
We have three boxes A, B, and C, each of which contains an integer.
Currently, the boxes A, B, and C contain the integers X, Y, and Z, respectively.
We will now do the operations below in order. Find the content of each box afterward.
·Swap the contents of the boxes A and B
·Swap the contents of the boxes A and C
Constraints
·1≤X,Y,Z≤100
·All values in input are integers.
输入
Input is given from Standard Input in the following format:
X Y Z
输出
Print the integers contained in the boxes A, B, and C, in this order, with space in between.
样例输入
【样例1】 1 2 3 【样例2】 100 100 100 【样例3】 41 59 31
样例输出
【样例1】 3 1 2 【样例2】 100 100 100 【样例3】 31 41 59
提示
样例1解释
After the contents of the boxes A and B are swapped, A, B, and C contain 2, 1, and 3, respectively.
Then, after the contents of A and C are swapped, A, B, and C contain 3, 1, and 2, respectively.
简单的三位交换,直接输出对应的字符。
#include<iostream>
#include<bits/stdc++.h>
#include<algorithm>
#include<string>
#include<stack>
#include<map>
#include<list>
#include<vector>
#include<queue>
#include<deque>
#include<set>
#include<functional>
#define pi 3.14159265358979323846264338327950288419716939937510582097494
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
#define _for(i, a, b) for(ll i = (a); i < (b); ++i)
#define _rep(i, a, b) for(ll i = (a); i <= (b); ++i)
#define _re_for(i, a, b) for(ll i = (a); i > (b); --i)
#define _re_rep(i, a, b) for(ll i = (a); i >= (b); --i)
const int INF1 = 0x3f3f3f3f;
const int INF0 = 0xc0c0c0c0;
const int MAX = 10010;
// INT_MAX INT_MIN
// DBL_MAX DBL_MIN
// -std=c++17 -Wl,--stack=536870914
ll a, b, c;
int main() {
cin >> a >> b >> c;
cout << c << ' ' << a << ' ' << b;
return 0;
}
问题 B: Popular Vote
时间限制: 1 Sec 内存限制: 128 MB
题目描述
We have held a popularity poll for N items on sale. Item i received Ai votes.
From these N items, we will select M as popular items. However, we cannot select an item with less than 1/4M of the total number of votes.
If M popular items can be selected, print Yes; otherwise, print No.
Constraints
·1≤M≤N≤100
·1≤Ai≤1000
·Ai are distinct.
·All values in input are integers.
输入
Input is given from Standard Input in the following format:
N M
A1 ... AN
输出
If M popular items can be selected, print Yes; otherwise, print No.
样例输入
【样例1】 4 1 5 4 2 1 【样例2】 3 2 380 19 1 【样例3】 12 3 4 56 78 901 2 345 67 890 123 45 6 789
样例输出
【样例1】 Yes 【样例2】 No 【样例3】 Yes
提示
样例1解释
There were 12 votes in total. The most popular item received 5 votes, and we can select it.
样例2解释
There were 400 votes in total. The second and third most popular items received less than 1/(4×2) of the total number of votes, so we cannot select them. Thus, we cannot select two popular items.
统计一下票数超过1 / (k * 4)的项目数量,数量足够就为“Yes”。
#include<iostream>
#include<bits/stdc++.h>
#include<algorithm>
#include<string>
#include<stack>
#include<map>
#include<list>
#include<vector>
#include<queue>
#include<deque>
#include<set>
#include<functional>
#define pi 3.14159265358979323846264338327950288419716939937510582097494
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
#define _for(i, a, b) for(ll i = (a); i < (b); ++i)
#define _rep(i, a, b) for(ll i = (a); i <= (b); ++i)
#define _re_for(i, a, b) for(ll i = (a); i > (b); --i)
#define _re_rep(i, a, b) for(ll i = (a); i >= (b); --i)
const int INF1 = 0x3f3f3f3f;
const int INF0 = 0xc0c0c0c0;
const int MAX = 10010;
// INT_MAX INT_MIN
// DBL_MAX DBL_MIN
// -std=c++17 -Wl,--stack=536870914
ll read() {
ll x = 0, f = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-') f = -1;
c = getchar();
}
while (isdigit(c)) x = x * 10 + (c - 48), c = getchar();
return x * f;
}
ll n, m, cnt;
double sum, flag, num;
vector<double>vec;
int main() {
n = read(), m = read();
_rep(i, 1, n) {
cin >> num;
vec.push_back(num);
sum += num;
}
flag = 1 / (4.0 * m);;
for (auto it : vec) if (it / sum >= flag) cnt++;
cnt >= m ? cout << "Yes" : cout << "No";
return 0;
}
问题 C: Replacing Integer
时间限制: 1 Sec 内存限制: 128 MB
题目描述
Given any integer x, Aoki can do the operation below.
Operation: Replace x with the absolute difference of x and K.
You are given the initial value of an integer N. Find the minimum possible value taken by N after Aoki does the operation zero or more times.
Constraints
·0≤N≤1018
·1≤K≤1018
·All values in input are integers.
输入
Input is given from Standard Input in the following format:
N K
输出
Print the minimum possible value taken by N after Aoki does the operation zero or more times.
样例输入
【样例1】 7 4 【样例2】 2 6 【样例3】 1000000000000000000 1
样例输出
【样例1】 1 【样例2】 2 【样例3】 0
提示
样例1解释
Initially, N=7.
After one operation, N becomes |7−4|=3.
After two operations, N becomes |3−4|=1, which is the minimum value taken by N.
样例2解释
N=2 after zero operations is the minimum.
给定俩数N、K,每次操作可使abs(N,K)替换N。求若干次操作中N的最小可能值。
数论。
从模拟的结果看,结果必定不超过N和K。而N每次增大或减少了K(取绝对值),若干次操作后,N的值不会超过K,K神奇地变成的了N的模数,最终N的值为N % K。
那么就从N、N % K、N % K再做一次模操作 这三个值中选最小的。
#include<iostream>
#include<bits/stdc++.h>
#include<algorithm>
#include<string>
#include<stack>
#include<map>
#include<list>
#include<vector>
#include<queue>
#include<deque>
#include<set>
#include<functional>
#define pi 3.14159265358979323846264338327950288419716939937510582097494
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
#define _for(i, a, b) for(ll i = (a); i < (b); ++i)
#define _rep(i, a, b) for(ll i = (a); i <= (b); ++i)
#define _re_for(i, a, b) for(ll i = (a); i > (b); --i)
#define _re_rep(i, a, b) for(ll i = (a); i >= (b); --i)
const int INF1 = 0x3f3f3f3f;
const int INF0 = 0xc0c0c0c0;
const int MAX = 10010;
// INT_MAX INT_MIN
// DBL_MAX DBL_MIN
// -std=c++17 -Wl,--stack=536870914
ll read() {
ll x = 0, f = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-') f = -1;
c = getchar();
}
while (isdigit(c)) x = x * 10 + (c - 48), c = getchar();
return x * f;
}
ll n, k;
int main() {
n = read();
k = read();
cout << min(n, min(n % k, abs(n % k - k)));
return 0;
}
问题 G: 七七七七
时间限制: 1 Sec 内存限制: 128 MB
题目描述
牛牛最近对7很感兴趣,他想到了一个问题。
牛牛想存n元钱,他决定第1天存1元,第2天存7元,第3天存49元,以此类推,每天存的钱是前一天的7倍。
牛牛想知道几天后,存款的总额能大于等于n元钱。
输入
第一行输入一个整数n,表示牛牛想存的钱数。
输出
一行一个整数表示答案。
样例输入
52
样例输出
3
提示
样例解释:3天后,牛牛的存款为1+7+49=57元。
对于40%的数据有n≤10。
对于100%的数据有1≤n≤10000。仅一行一个字符串s,表示牛牛的密码。
数论,等比数列求和,q = 7,a1 = 1,逆向推导n = 7(1 + 6 * N)
#include<iostream>
#include<bits/stdc++.h>
#include<algorithm>
#include<string>
#include<stack>
#include<map>
#include<list>
#include<vector>
#include<queue>
#include<deque>
#include<set>
#include<functional>
#define pi 3.14159265358979323846264338327950288419716939937510582097494
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
#define _for(i, a, b) for(ll i = (a); i < (b); ++i)
#define _rep(i, a, b) for(ll i = (a); i <= (b); ++i)
#define _re_for(i, a, b) for(ll i = (a); i > (b); --i)
#define _re_rep(i, a, b) for(ll i = (a); i >= (b); --i)
const int INF1 = 0x3f3f3f3f;
const int INF0 = 0xc0c0c0c0;
const int MAX = 10010;
// INT_MAX INT_MIN
// DBL_MAX DBL_MIN
// -std=c++17 -Wl,--stack=536870914
ll sn;
int main() {
cin >> sn;
cout << ceil(log(1 + 6 * sn) / log(7));
return 0;
}
问题 I: 小球下落
时间限制: 1 Sec 内存限制: 128 MB
题目描述
有一块大小为n行2列的板子,每个位置可能是一个小球,用'o'表示,可能是障碍物,用'x'表示,也可能空无一物,用'.'来表示。
每个小球可以向左向右或者向下移动,但是不能向上移动,或者和某个小球重叠,也不能越出板子。
每个小球向下移动一个单位,牛牛可以获得一分。
输入
第一行输入一个整数n,表示板子的行数。
随后n行,每行一个长度为2的字符串,如题意所示。
设有k个小球。
输出
一行,一个整数,表示牛牛能得到的最大分数。
样例输入
10 oo .o .x x. .. oo .o x. .. x.
样例输出
12
提示
样例解释
最终结果为:
..
oo
ox
x.
..
..
..
x.
oo
xo。
对于20%的数据有n≤3。
另有20%的数据k≤10。
对于60%的数据有n≤1000。
对于100%的数据有1≤n≤300000。
DFS暴搜,不过是反过来自底向上DFS点为‘o'向下可以移动的层级。
.x
x.
x.
xo
ox
xx
类似于此的排布便是不可移动
每次dfs得到的层数便是移动该球可得到的分数,dfs后将球更改位置。
#include<iostream>
#include<bits/stdc++.h>
#include<algorithm>
#include<string>
#include<stack>
#include<map>
#include<list>
#include<vector>
#include<queue>
#include<deque>
#include<set>
#include<functional>
#define pi 3.14159265358979323846264338327950288419716939937510582097494
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
#define _for(i, a, b) for(ll i = (a); i < (b); ++i)
#define _rep(i, a, b) for(ll i = (a); i <= (b); ++i)
#define _re_for(i, a, b) for(ll i = (a); i > (b); --i)
#define _re_rep(i, a, b) for(ll i = (a); i >= (b); --i)
const int INF1 = 0x3f3f3f3f;
const int INF0 = 0xc0c0c0c0;
const int MAX = 300010;
// INT_MAX INT_MIN
// DBL_MAX DBL_MIN
// -std=c++17 -Wl,--stack=536870914
ll n, ans;
vector<char> vec[MAX];
ll dfs(ll i, ll j) {
if (i == n) return i;
if (vec[i + 1][j] != '.' && (vec[i + 1][1 - j] != '.' || vec[i][1 - j] != '.')) return i;
if (vec[i + 1][j] == vec[i + 1][1 - j]) return max(dfs(i + 1, j), dfs(i + 1, 1 - j));
else {
if (vec[i + 1][j] == '.') return dfs(i + 1, j);
else return dfs(i + 1, 1 - j);
}
}
int main() {
cin >> n;
_rep(i, 1, n) {
vec[i].push_back(getchar());
vec[i].push_back(getchar());
getchar();
}
_re_rep(i, n, 1) {
_rep(j, 0, 1) {
if (vec[i][j] == 'o') {
vec[i][j] = '.';
ll temp = dfs(i, j);
ans += (temp - i);
if (vec[temp][0] == vec[temp][1]) vec[temp - 1][0] == 'x' ? vec[temp][0] = 'o' : vec[temp][1] = 'o';
else vec[temp][0] == '.' ? vec[temp][0] = 'o' : vec[temp][1] = 'o';
}
}
if (vec[i][0] == 'o') {
vec[i][0] = '.';
ll temp = dfs(i, 0);
ans += (temp - i);
if (vec[temp][0] == vec[temp][1]) vec[temp - 1][0] == 'x' ? vec[temp][0] = 'o' : vec[temp][1] = 'o';
else vec[temp][0] == '.' ? vec[temp][0] = 'o' : vec[temp][1] = 'o';
}
}
cout << ans;
return 0;
}