问题 A: Coffee
时间限制: 1 Sec 内存限制: 128 MB
题目描述
A string of length 6 consisting of lowercase English letters is said to be coffee-like if and only if its 3-rd and 4-th characters are equal and its 5-th and 6-th characters are also equal.
Given a string S, determine whether it is coffee-like.
Constraints
·S is a string of length 6 consisting of lowercase English letters.
输入
Input is given from Standard Input in the following format:
S
输出
If S is coffee-like, print Yes; otherwise, print No.
样例输入
【样例1】
sippuu
【样例2】
iphone
【样例3】
coffee
样例输出
【样例1】
Yes
【样例2】
No
【样例3】
Yes
提示
样例1解释
In sippuu, the 3-rd and 4-th characters are equal, and the 5-th and 6-th characters are also equal.
#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;
#define _for(i, a, b) for(unsigned int i=(a);i<(b);++i)
#define _rep(i, a, b) for(unsigned int i=(a);i<=(b);++i)
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
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;
}
double mysqrt(double num, double mi) {
return pow(num, 1 / mi);
}
typedef struct {
double cost;
double wei;
double pre;
} typestruct;
bool cmp(typestruct stu1, typestruct stu2) {
if (stu1.pre == stu2.pre) {
return stu1.wei > stu2.wei;
}
return stu1.pre > stu2.pre;
}
string s;
int main() {
cin >> s;
if (s[2] == s[3] && s[4] == s[5]) cout << "Yes";
else cout << "No";
return 0;
}
问题 B: Golden Coins
时间限制: 1 Sec 内存限制: 128 MB
题目描述
Takahashi loves gold coins. He gains 1000 happiness points for each 500-yen coin he has and gains
5 happiness points for each 5-yen coin he has. (Yen is the currency of Japan.)
Takahashi has X yen. If he exchanges his money so that he will gain the most happiness points, how many happiness points will he earn?
(We assume that there are six kinds of coins available: 500-yen, 100-yen, 50-yen, 10-yen, 5-yen, and 1-yen coins.)
Constraints
·0≤X≤109
·X is an integer.
输入
Input is given from Standard Input in the following format:
X
输出
Print the maximum number of happiness points that can be earned.
样例输入
【样例1】
1024
【样例2】
0
【样例3】
1000000000
样例输出
【样例1】
2020
【样例2】
0
【样例3】
2000000000
提示
样例1解释
By exchanging his money so that he gets two 500-yen coins and four 5-yen coins, he gains 2020 happiness points, which is the maximum number of happiness points that can be earned.
样例2解释
He is penniless - or yenless.
样例3解释
He is a billionaire - in yen.
#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;
#define _for(i, a, b) for(unsigned int i=(a);i<(b);++i)
#define _rep(i, a, b) for(unsigned int i=(a);i<=(b);++i)
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
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;
}
double mysqrt(double num, double mi) {
return pow(num, 1 / mi);
}
typedef struct {
double cost;
double wei;
double pre;
} typestruct;
bool cmp(typestruct stu1, typestruct stu2) {
if (stu1.pre == stu2.pre) {
return stu1.wei > stu2.wei;
}
return stu1.pre > stu2.pre;
}
ll n;
int main() {
n = read();
cout << (n / 500 * 1000) + (n % 500 / 5 * 5);
return 0;
}
问题 C: Traveling Salesman around Lake
时间限制: 1 Sec 内存限制: 128 MB
题目描述
There is a circular pond with a perimeter of K meters, and N houses around them.
The i-th house is built at a distance of Ai meters from the northmost point of the pond, measured clockwise around the pond.
When traveling between these houses, you can only go around the pond.
Find the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.
Constraints
·2≤K≤106
·2≤N≤2×105
·0≤A1<...<AN<K
·All values in input are integers.
输入
Input is given from Standard Input in the following format:
K N
A1 A2 ... AN
输出
Print the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.
样例输入
【样例1】
20 3
5 10 15
【样例2】
20 3
0 5 15
样例输出
【样例1】
10
【样例2】
10
提示
样例1解释
If you start at the 1-st house and go to the 2-nd and 3-rd houses in this order, the total distance traveled will be 10.
样例2解释
If you start at the 2-nd house and go to the 1-st and 3-rd houses in this order, the total distance traveled will be 10.
#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;
#define _for(i, a, b) for(unsigned int i=(a);i<(b);++i)
#define _rep(i, a, b) for(unsigned int i=(a);i<=(b);++i)
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
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;
}
double mysqrt(double num, double mi) {
return pow(num, 1 / mi);
}
typedef struct {
double cost;
double wei;
double pre;
} typestruct;
bool cmp(typestruct stu1, typestruct stu2) {
if (stu1.pre == stu2.pre) {
return stu1.wei > stu2.wei;
}
return stu1.pre > stu2.pre;
}
ll k, n, maxlenth;
vector<ll>vec;
int main() {
k = read(), n = read();
_rep(i, 1, n) {
vec.push_back(read());
if (i >= 2) maxlenth = max(maxlenth, abs(vec.back() - vec[i - 2]));
}
if (n == 1) {
cout << 0;
return 0;
}
maxlenth = max(maxlenth, abs(vec.back() - k) + vec.front());
cout << k - maxlenth;
return 0;
}
问题 G: 购物
时间限制: 1 Sec 内存限制: 128 MB
题目描述
超市进行了买k送一的活动,商品的单价是x元,牛妹想至少买n件商品,输出最少需要花费多少钱。
输入
第一行一个整数T<=100,表示T组数据。
接下来T行,每行3个整数n,k,x(1≤n,x≤1000,1≤k≤100)
输出
对于每组数据输出一行表示答案。
样例输入
3
3 2 1
10 3 4
5 3 2
样例输出
2
32
8
#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;
#define _for(i, a, b) for(unsigned int i=(a);i<(b);++i)
#define _rep(i, a, b) for(unsigned int i=(a);i<=(b);++i)
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
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;
}
double mysqrt(double num, double mi) {
return pow(num, 1 / mi);
}
typedef struct {
double cost;
double wei;
double pre;
} typestruct;
bool cmp(typestruct stu1, typestruct stu2) {
if (stu1.pre == stu2.pre) {
return stu1.wei > stu2.wei;
}
return stu1.pre > stu2.pre;
}
ll t, n, k, x;
int main() {
t = read();
while (t--) {
cin >> n >> k >> x;
ll zu = n / (k + 1);
ll cha = n - zu * (k + 1);
cout << cha * x + zu * k * x << endl;
}
return 0;
}
问题 H: 交换
时间限制: 1 Sec 内存限制: 128 MB
题目描述
给一个长度为n的01序列s[1],s[2],....,s[n],现在可以至多进行1次如下操作:
选择1≤x<n,将s序列变成s[x+1],s[x+2],…..s[n],s[1],s[2],….s[x]
输出最长的全为1的子区间长度。
输入
一个01字符串,表示序列s。(1<=|s|<=100000)
输出
输出一个整数表示答案。
样例输入
【样例1】
1001
【样例2】
11111
【样例3】
10111010
样例输出
【样例1】
2
【样例2】
5
【样例3】
3
#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;
#define _for(i, a, b) for(unsigned int i=(a);i<(b);++i)
#define _rep(i, a, b) for(unsigned int i=(a);i<=(b);++i)
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
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;
}
double mysqrt(double num, double mi) {
return pow(num, 1 / mi);
}
typedef struct {
double cost;
double wei;
double pre;
} typestruct;
bool cmp(typestruct stu1, typestruct stu2) {
if (stu1.pre == stu2.pre) {
return stu1.wei > stu2.wei;
}
return stu1.pre > stu2.pre;
}
string s;
int cnt, ans;
int main() {
cin >> s;
for (auto it : s) {
if (it != '1') {
ans = max(ans, cnt);
cnt = 0;
} else cnt++;
}
ans = max(ans, cnt);
if (ans == s.size()) {
cout << ans;
return 0;
}
if (s.front() == '1' && s.back() == '1') {
int l = 0, r = 0;
for (int i = 0; s[i] == '1'; i++) l++;
for (int i = s.size() - 1; s[i] == '1'; i--) r++;
ans = max(ans, l + r);
}
cout << ans;
return 0;
}