A. Rudolf and the Ticket
题意:问有多少组数字可以满足。
题解:枚举统计答案即可。
代码:
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
const int maxn = 1e6 + 7 ;
const int mod = 998244353 ;
inline ll read() {
ll x = 0, f = 1 ;
char c = getchar() ;
while (c > '9' || c < '0') {
if (c == '-')
f = -1 ;
c = getchar() ;
}
while (c >= '0' && c <= '9') {
x = x * 10 + c - '0' ;
c = getchar() ;
}
return x * f ;
}
ll t , n , d , k , m , b[maxn] , a[maxn] ;
void solve(){
n = read() ;
m = read() ;
k = read() ;
for(int i = 1 ; i <= n ; i ++){
a[i] = read() ;
}
for(int i = 1 ; i <= m ; i ++){
b[i] = read() ;
}
ll ans = 0 ;
for(int i = 1 ; i <= n ; i ++){
for(int j = 1 ; j <= m ; j ++){
if(a[i] + b[j] <= k){
ans ++ ;
}
}
}
cout << ans << endl ;
}
int main(){
t = read() ;
while(t --){
solve() ;
}
return 0 ;
}
B. Rudolf and 121
题意:给你n个数字,有一个操作,会使,看看能不能让所有数字变成0。
题解:最左边的数字在这一轮必须变成0,因为i从2往右走,只有一次机会让变成0,所以直接枚举,每次取,遍历一遍从2 - n - 1看看能否将数组全部变成0即可。
代码:
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
const int maxn = 1e6 + 7 ;
const int mod = 998244353 ;
inline ll read() {
ll x = 0, f = 1 ;
char c = getchar() ;
while (c > '9' || c < '0') {
if (c == '-')
f = -1 ;
c = getchar() ;
}
while (c >= '0' && c <= '9') {
x = x * 10 + c - '0' ;
c = getchar() ;
}
return x * f ;
}
ll t , n , d , k , m , b[maxn] , a[maxn] ;
void solve(){
n = read() ;
for(int i = 1 ; i <= n ; i ++){
a[i] = read() ;
}
for(int i = 2 ; i <= n - 1 ; i ++){
ll res = max(a[i - 1] , 0ll) ;
a[i] -= res * 2 ;
a[i - 1] -= res ;
a[i + 1] -= res ;
}
for(int i = 1 ; i <= n ; i ++){
if(a[i] != 0){
cout << "NO\n" ;
return ;
}
}
cout << "YES\n" ;
}
int main(){
t = read() ;
while(t --){
solve() ;
}
return 0 ;
}
C. Rudolf and the Ugly String
题意:有两个字符串,“pie”和“map”,问最少进行多少操作可以使字符串里不包含这两个字符串。
题解:看看样例,很容易发现不管是“pie”还是“map”,就拿“pie”做例子,有可能会有很多p也有可能有很多e,如果都去掉肯定不最优,那明显就去中间的字母,因为如果中间字母有很多个,那就组不成“pie”,“map”同理,只需要再想一个特殊的情况,如果字符串是“mapie”,那么只需要去掉p即可。所以直接枚举,判断累加答案即可。
代码:
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
const int maxn = 1e6 + 7 ;
const int mod = 998244353 ;
inline ll read() {
ll x = 0, f = 1 ;
char c = getchar() ;
while (c > '9' || c < '0') {
if (c == '-')
f = -1 ;
c = getchar() ;
}
while (c >= '0' && c <= '9') {
x = x * 10 + c - '0' ;
c = getchar() ;
}
return x * f ;
}
ll t , n , d , k , m , b[maxn] , a[maxn] ;
char s[maxn] ;
void solve(){
n = read() ;
scanf("%s" , s + 1) ;
int rt = 1 ;
ll ans = 0 ;
while(1){
// cout << rt << endl ;
if(rt >= n){
break ;
}
if(rt + 4 <= n){
string ss = "" ;
for(int i = rt ; i <= rt + 4 ; i ++){
ss = ss + s[i] ;
}
if(ss == "mapie"){
ans ++ ;
rt = rt + 4 ;
continue ;
}
}
if(rt + 2 <= n){
string ss = "" ;
for(int i = rt ; i <= rt + 2 ; i ++){
ss = ss + s[i] ;
}
if(ss == "map" || ss == "pie"){
ans += 1 ;
rt = rt + 2 ;
continue ;
}
}
rt ++ ;
}
cout << ans << endl ;
}
int main(){
t = read() ;
while(t --){
solve() ;
}
return 0 ;
}
D. Rudolf and the Ball Game
题意:给你n个数,m次操作,开始的时候球在k的手里,有三种操作,第一种是“0”,让球顺时针传递x个人,第二种是“1”,让球逆时针传递x个人,第三种是“?”,不确定方向,可以顺时针传递也可以逆时针传递,问球最终可能在哪些人手上,按数字大小顺序输出。
题解:首先可以想到dfs搜索,很好处理,看到m的数据范围是1000,那明显不行,那就想到用数据结构或者STL来维护数字,一开始我觉得不太行,因为数据范围都是1000,那么乘起来肯定爆掉了,但是看到,再想,就算是每个操作是“?” , 最多每次只会出现n个数字,有m次操作,那么最多的操作数就是n * m,再加上STL维护的复杂度,那么就是,很明显能过掉,求解成功。
代码:
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
const int maxn = 1e6 + 7 ;
const int mod = 998244353 ;
inline ll read() {
ll x = 0, f = 1 ;
char c = getchar() ;
while (c > '9' || c < '0') {
if (c == '-')
f = -1 ;
c = getchar() ;
}
while (c >= '0' && c <= '9') {
x = x * 10 + c - '0' ;
c = getchar() ;
}
return x * f ;
}
ll t , n , d , k , m , b[maxn] , a[maxn] ;
char s[maxn] ;
vector < int > q ;
void solve(){
q.clear() ;
n = read() ;
m = read() ;
k = read() ;
q.push_back(k) ;
for(int i = 1 ; i <= m ; i ++){
ll u ;
u = read() ;
char c ;
cin >> c ;
if(c == '?'){
set < int > p ;
for(int j = 0 ; j < (int)q.size() ; j ++){
p.insert(((q[j] + u) % n) == 0 ? n : (q[j] + u) % n) ;
p.insert(((q[j] + n - u) % n) == 0 ? n : (q[j] + n - u) % n) ;
}
q.clear() ;
for(auto it : p){
q.push_back(it) ;
}
}
if(c == '1'){
set < int > p ;
for(int j = 0 ; j < (int)q.size() ; j ++){
p.insert(((q[j] + n - u) % n) == 0 ? n : (q[j] + n - u) % n) ;
}
q.clear() ;
for(auto it : p){
q.push_back(it) ;
}
}
if(c == '0'){
set < int > p ;
for(int j = 0 ; j < (int)q.size() ; j ++){
p.insert(((q[j] + u) % n) == 0 ? n : (q[j] + u) % n) ;
}
q.clear() ;
for(auto it : p){
q.push_back(it) ;
}
}
}
sort(q.begin() , q.end()) ;
cout << q.size() << endl ;
for(int i = 0 ; i < (int)q.size() ; i ++){
cout << q[i] << " " ;
}
cout << endl ;
}
int main(){
t = read() ;
while(t --){
solve() ;
}
return 0 ;
}