问题 A: God Sequence
时间限制: 1 Sec 内存限制: 128 MB Special Judge
题目描述
A sequence of length A+B, E=(E1,E2,…,EA+B), that satisfies all of the conditions below is said to be a god sequence.
E1+E2+⋯+EA+B=0 holds.
There are exactly A positive integers among E1,E2,…,EA+B.
There are exactly B negative integers among E1,E2,…,EA+B.
E1,E2,…,EA+B are all distinct.
−109≤Ei≤109,Ei≠0 holds for every i (1≤i≤A+B).
Construct one god sequence.
We can prove that at least one god sequence exists under Constraints of this problem.
Constraints
1≤A≤1000
1≤B≤1000
All values in input are integers.
输入
Input is given from Standard Input in the following format:
A B
输出
Print the elements of your sequence in one line, with space as separator.
If there are multiple god sequences, any of them will be accepted.
E1 E2 ⋯ EA+B
样例输入
【样例1】
1 1
【样例2】
1 4
【样例3】
7 5
样例输出
【样例1】
1001 -1001
【样例2】
-8 -6 -9 120 -97
【样例3】
323 -320 411 206 -259 298 -177 -564 167 392 -628 151
提示
样例1解释
A sequence (1001,−1001) contains A=1 positive integer and B=1 negative integer totaling 1001+(−1001)=0.
It also satisfies the other conditions and thus is a god sequence.
样例2解释
A sequence (−8,−6,−9,120,−97) contains A=1 positive integer and B=4 negative integers totaling (−8)+(−6)+(−9)+120+(−97)=0.
It also satisfies the other conditions and thus is a god sequence.
#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>
#include<limits.h>
#include<float.h>
#define pi 3.14159265358979323846264338327950288419716939937510582097494
using namespace std;
#define _for(i, a, b) for( int i=(a);i<(b);++i)
#define _rep(i, a, b) for( int i=(a);i<=(b);++i)
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
// INT_MAX INT_MIN
// DBL_MAX DBL_MIN
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 a, b;
ll sum1, sum2;
int main() {
a = read();
b = read();
if (a >= b) {
_rep(i, 1, a) {
cout << i << ' ';
sum1 += i;
}
_rep(i, 1, b - 1) {
cout << -i << ' ';
sum2 += i;
}
cout << sum2 - sum1;
} else {
_rep(i, 1, b) {
cout << -i << ' ';
sum1 += i;
}
_rep(i, 1, a - 1) {
cout << i << ' ';
sum2 += i;
}
cout << sum1 - sum2;
}
return 0;
}
问题 B: ARC Wrecker
时间限制: 1 Sec 内存限制: 128 MB
题目描述
There are N buildings along AtCoder road. Initially, the i-th building from the left has Ai stories.
Takahashi, the president of ARC Wrecker, Inc., can do the following operation any number of times, possibly zero:
Choose a positive integer X that he likes and shoot a cannonball at that height, which decreases by 1 the number of stories in each building with X or more stories.
Find the number of possible final sceneries of buildings, modulo (109+7).
We consider two sceneries A and B different when the following holds:
let Pi be the number of stories of the i-th building from the left in scenery A;
let Qi be the number of stories of the i-th building from the left in scenery B;
we consider sceneries A and B different when Pi≠Qi for one or more indices i.
Constraints
1≤N≤100000
1≤Ai≤109
All values in input are integers.
输入
Input is given from Standard Input in the following format:
N
A1 A2 ⋯ AN
输出
Print the answer.
样例输入
【样例1】
2
1 2
【样例2】
6
5 3 4 1 5 2
【样例3】
7
314 159 265 358 979 323 846
样例输出
【样例1】
4
【样例2】
32
【样例3】
492018656
提示
样例1解释
There are four possible combinations of heights of the buildings, as follows:
(Building 1, Building 2) = (0,0)
(Building 1, Building 2) = (0,1)
(Building 1, Building 2) = (1,1)
(Building 1, Building 2) = (1,2)
样例3解释
There are 20192492160000 possible final sceneries. The correct output is that number modulo 109+7, which is 492018656.
#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>
#include<limits.h>
#include<float.h>
#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)
#define _re_for(i, a, b) for(unsigned int i=(a);i>(b);--i)
#define _re_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;
// INT_MAX INT_MIN
// DBL_MAX DBL_MIN
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 num;
ll mod = 1e9 + 7, ans = 1;
int main() {
vector<ll>vec;
vec.push_back(0);
ll n = 0;
n = read();
_rep(i, 1, n) {
num = read();
if (num != vec.back()) vec.push_back(num);
}
sort(vec.begin(), vec.end());
_re_rep(i, vec.size() - 1, 1) ans = (ans * (vec[i] - vec[i - 1] + 1)) % mod;
cout << ans;
return 0;
}
问题 G: 展示玩具
时间限制: 1 Sec 内存限制: 128 MB
题目描述
一年一度的圣诞节快来临了,玩具公司为此生产了不同类型的圣诞玩具。为了让更多的大小朋友能够买到他们喜欢的玩具,公司决定将这 n 种类型的玩具在江北万达里展示出来。
由于玩具实在太多了,不一定能将所有的玩具一一展示出来。今年的圣诞节大老板泽泽会亲临现扬,他是一个很奇怪的人,他希望每次展示出来的玩具大小尽可能地接近,他不允许展示出来的玩具中有两个玩具的大小差距超过 k。现在给你这个整数 k,请你帮助泽泽计算最多有多少个玩具可以同时被展示出来。
输入
输入两个整数 n 和 k,n 表示玩具的总数,k 表示最大的差值。
下面 n 行,每行输入一个整数 ai,分别表示玩具的尺寸大小。
输出
输出一个整数,表示最多可以展示的玩具总数。
样例输入
6 3
1
8
4
3
1
2
样例输出
5
提示
尺寸大小为 1,1,2,3,4 这 5 个玩具可同时展示出来,其中最大的玩具和最小的玩具尺寸之差只有 3,刚好。
1<=n<=5000;
0<=k<=5000;
每个玩具的尺寸都是正整数不超过 5000。
#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>
#include<limits.h>
#include<float.h>
#define pi 3.14159265358979323846264338327950288419716939937510582097494
using namespace std;
#define _for(i, a, b) for(int i=(a);i<(b);++i)
#define _rep(i, a, b) for(int i=(a);i<=(b);++i)
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
// INT_MAX INT_MIN
// DBL_MAX DBL_MIN
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 lis[10050];
ll qz[10050];
ll n, k, num, maxnum, maxcnt;
ll ans;
int main() {
n = read();
k = read();
_rep(i, 1, n) {
num = read();
maxnum = max(maxnum, num);
lis[num] ++;
maxcnt = max(maxcnt, lis[num]);
}
if (k == 0) {
cout << maxcnt;
return 0;
}
qz[1] = lis[1];
_rep(i, 2, maxnum + k) qz[i] = qz[i - 1] + lis[i];
_rep(i, 1, maxnum) {
ans = max(ans, qz[i + k] - qz[i - 1]);
}
cout << ans;
return 0;
}
问题 K: 促销骰子
时间限制: 1 Sec 内存限制: 128 MB
题目描述
小爱的商店正在做促销活动。顾客在付款的时候,有机会掷一次骰子,如果掷出 6,可以获得优惠,并且可以继续掷骰子,直到出现不是 6 的情况,或掷三次为止。获奖规则如下:
如果只有一个 6,优惠 10 元;
如果有两个 6,优惠 100 元;
如果有三个 6,优惠 1000 元。
给定一组投掷的结果,请输出可以获得的优惠金额。
输入
输入由最多三个整数构成,中间由空格分开:
若输入有三个数字,则保证前两个数字为 6;
若输入有两个数字,则保证第一个数字为 6,后一个数字不为 6;
若输入只有一个数字,则保证该数字不为 6。
输出
单个整数:表示获得的优惠金额。
样例输入
【样例1】
6 3
【样例2】
6 6 6
【样例3】
1
样例输出
【样例1】
10
【样例2】
1000
【样例3】
0
提示
保证输入的每个数字在 1 到 6 之间。
#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>
#include<limits.h>
#include<float.h>
#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;
// INT_MAX INT_MIN
// DBL_MAX DBL_MIN
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;
}
int st[3];
int main() {
int i = 0;
while (cin >> st[i++]);
if (st[0] == 6) {
if (st[1] == 6) {
if (st[2] == 6) cout << 1000;
else cout << 100;
} else cout << 10;
} else cout << 0;
return 0;
}