A. Maliang Learning Painting
题意:马良在沙子,石头,洞壁的画画,求总和
思路:水题,a+b+c
ac代码:
#include<bits/stdc++.h>
using namespace std;
#define lll __int128
#define endl '\n'
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> PII;
const int mod=1e9+7;
inline ll read()
{
ll x = 0, y = 1;
char c = getchar();
while (!isdigit(c))
{
if (c == '-')
y = -1;
c = getchar();
}
while (isdigit(c))
{
x = (x << 3) + (x << 1) + (c ^ 48);
c = getchar();
}
return x *= y;
}
inline void write(ll x)
{
if (x < 0)
x = -x, putchar('-');
ll sta[35], top = 0;
do
sta[top++] = x % 10, x /= 10;
while (x);
while (top)
putchar(sta[--top] + '0');
}
void Miraitowa(){
ll a, b, c;
cin >> a >> b >> c;
ll res = a + b + c;
cout << res << endl;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
// int t;
// cin>>t;
// while(t--)
Miraitowa();
return 0;
};
C.Liar
题意:n个玩家每人分配一个整数,总和为s,每个玩家声称自己分配的是a,求最多说真话的人
思路:要求说真话最多的人,如果每个人相加的和为s则都说的真话,否则的话,肯定至少有一个人说了假话,为了使说真话的人最多,我们可以先算n-1个人的总和,剩下的那个人说了假话,说假话的人的真实分配的数为s-s1
(不要被玩家声称的数的范围迷惑)
ac代码:
#include<bits/stdc++.h>
using namespace std;
#define lll __int128
#define endl '\n'
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> PII;
const int mod=1e9+7;
inline ll read()
{
ll x = 0, y = 1;
char c = getchar();
while (!isdigit(c))
{
if (c == '-')
y = -1;
c = getchar();
}
while (isdigit(c))
{
x = (x << 3) + (x << 1) + (c ^ 48);
c = getchar();
}
return x *= y;
}
inline void write(ll x)
{
if (x < 0)
x = -x, putchar('-');
ll sta[35], top = 0;
do
sta[top++] = x % 10, x /= 10;
while (x);
while (top)
putchar(sta[--top] + '0');
}
const int N = 3e5 + 10;
ll a[N];
void Miraitowa(){
ll n,s;
cin >> n >> s;
ll res = 0;
for (int i = 1; i <= n;i++){
cin >> a[i];
res += a[i];
}
if(res==s) cout << n << endl;
else
cout << n - 1 << endl;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
// int t;
// cin>>t;
// while(t--)
Miraitowa();
return 0;
};
G. Multiples of 5
题意:通过特定的输入方式得到一个11进制的数,求这个数转换成10进制后这个数是不是5的倍数
思路:首先要将11进制转换成10进制,每一位都要乘以相应的11次方获得的数相加,因此每一位转化都不会相互影响,所以可以每一位%5后相加,无论11的多少此方%5后都是1,所以每一位的贡献都是11进制下每一位%5后乘以有多少个的结果,最后加起来以后%5
ac代码:
#include<bits/stdc++.h>
using namespace std;
#define lll __int128
#define endl '\n'
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> PII;
const int mod=1e9+7;
inline ll read()
{
ll x = 0, y = 1;
char c = getchar();
while (!isdigit(c))
{
if (c == '-')
y = -1;
c = getchar();
}
while (isdigit(c))
{
x = (x << 3) + (x << 1) + (c ^ 48);
c = getchar();
}
return x *= y;
}
inline void write(ll x)
{
if (x < 0)
x = -x, putchar('-');
ll sta[35], top = 0;
do
sta[top++] = x % 10, x /= 10;
while (x);
while (top)
putchar(sta[--top] + '0');
}
void Miraitowa(){
ll n;
cin >> n;
ll res = 0;
for (int i = 0; i < n;i++){
ll a;
char b;
cin >> a >> b;
if(b!='A') res = (res + a*(b - '0')%5) % 5;
}
if (!res)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
int t;
cin>>t;
while(t--)
Miraitowa();
return 0;
};
H.Convolution
题意:给你两个二维矩阵,一个是原始矩阵,一个是卷积核,通过卷积网络模式来得到一个最后答案的矩阵,求该矩阵的和,矩阵核自定义选1,0,-1,求最大和
思路:卷积核每一位不定,但是通过卷积网络计算公式可以发现每一位做出的贡献是原数组的一个二维子矩阵,那么我们可以先求这个子矩阵里的和,当和小于0时,要使得最后和最大,那么当前位数需要为-1,否则为1,
可以用二维前缀和矩阵来求解
ac代码:
#include <bits/stdc++.h>
using namespace std;
#define lll __int128
#define endl '\n'
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> PII;
const int mod = 1e9 + 7;
inline ll read()
{
ll x = 0, y = 1;
char c = getchar();
while (!isdigit(c))
{
if (c == '-')
y = -1;
c = getchar();
}
while (isdigit(c))
{
x = (x << 3) + (x << 1) + (c ^ 48);
c = getchar();
}
return x *= y;
}
inline void write(ll x)
{
if (x < 0)
x = -x, putchar('-');
ll sta[35], top = 0;
do
sta[top++] = x % 10, x /= 10;
while (x);
while (top)
putchar(sta[--top] + '0');
}
const int N = 3000;
ll vec[N][N];
void Miraitowa()
{
ll n, m, a, b;
cin >> n >> m >> a >> b;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
cin >> vec[i][j];
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
vec[i][j] += vec[i - 1][j] + vec[i][j - 1] - vec[i - 1][j - 1];
ll ans = 0;
for (int i = 1; i <= a; i++)
{
for (int j = 1; j <= b; j++)
{
ll l = n - a + i, r = m - b + j;
ans += abs(vec[l][r] - vec[i - 1][r] - vec[l][j - 1] + vec[i - 1][j - 1]);
}
}
cout << ans;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
// int t;
// cin>>t;
// while(t--)
Miraitowa();
return 0;
};
J.Magic Mahjong
题意:打麻将,给一个字符串,判断是不是两种胜利方式,要么十三幺,要么七个对
思路:模拟,先将字符串分割存到map里然后模拟判断即可
ac代码
#include<bits/stdc++.h>
using namespace std;
#define lll __int128
#define endl '\n'
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> PII;
const int mod=1e9+7;
inline ll read()
{
ll x = 0, y = 1;
char c = getchar();
while (!isdigit(c))
{
if (c == '-')
y = -1;
c = getchar();
}
while (isdigit(c))
{
x = (x << 3) + (x << 1) + (c ^ 48);
c = getchar();
}
return x *= y;
}
inline void write(ll x)
{
if (x < 0)
x = -x, putchar('-');
ll sta[35], top = 0;
do
sta[top++] = x % 10, x /= 10;
while (x);
while (top)
putchar(sta[--top] + '0');
}
void Miraitowa(){
string s;
cin >> s;
map<string, ll> mp;
for (int i = 0; i < s.size();i+=2)
mp[s.substr(i, 2)]++;
set<string> se;
se.insert("1z");
se.insert("2z");
se.insert("3z");
se.insert("4z");
se.insert("5z");
se.insert("6z");
se.insert("7z");
se.insert("1p");
se.insert("9p");
se.insert("1s");
se.insert("9s");
se.insert("1m");
se.insert("9m");
if (mp.size() == 7)
cout << "7 Pairs" << endl;
else{
if(mp.size()==13){
for(auto it:mp)
if(!se.count(it.first)){
cout << "Otherwise" << endl;
return;
}
cout << "Thirteen Orphans" << endl;
}else
cout << "Otherwise" << endl;
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
int t;
cin>>t;
while(t--)
Miraitowa();
return 0;
};
K.Magic Tree
题意:两行m列,求能组成树的个数
思路:每次换行会有俩分支,往回走是思路只能往右走或者再次换行,模拟一下1,2,3,4,可以发现最后答案为1,2,4,8,可以猜测一手答案为2 n-1
ac代码
#include<bits/stdc++.h>
using namespace std;
#define lll __int128
#define endl '\n'
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> PII;
const int mod = 998244353;
inline ll read()
{
ll x = 0, y = 1;
char c = getchar();
while (!isdigit(c))
{
if (c == '-')
y = -1;
c = getchar();
}
while (isdigit(c))
{
x = (x << 3) + (x << 1) + (c ^ 48);
c = getchar();
}
return x *= y;
}
inline void write(ll x)
{
if (x < 0)
x = -x, putchar('-');
ll sta[35], top = 0;
do
sta[top++] = x % 10, x /= 10;
while (x);
while (top)
putchar(sta[--top] + '0');
}
ll qmi(ll a,ll b){
ll res = 1;
while(b){
if(b&1) res = res * a % mod;
b >>= 1;
a = a * a % mod;
}
return res;
}
void Miraitowa(){
ll n;
cin >> n;
cout << qmi(2, n - 1) << endl;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
// int t;
// cin>>t;
// while(t--)
Miraitowa();
return 0;
};