个人题解 | 转载
个人题解
原文Link: [https://zhuanlan.zhihu.com/p/697058078]
今天尝试和队友vp了22年山东省赛,被暴杀了,捡了个银尾;然后今晚牛客小白也被暴杀了...
这辈子没写过这么多数学(悲)
A.
签到
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<queue>
#include<map>
#include<cmath>
#include<vector>
#define ll long long
using namespace std;
bool check(ll num){
if(num%7==0)return true;
string s=to_string(num);
for(int i=0;i<s.size();i++){
if(s[i]=='7'){
return true;
}
}
return false;
}
int main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int t;cin>>t;
while(t--){
int n,a,k;
cin>>n>>a>>k;
for(int i=a+1,j=1;j<=k;i+=n,j++){
if(check(i)){
cout<<'p'<<" ";
}
else{
cout<<i<<" ";
}
}
cout<<'\n';
}
return 0;
}
B.
一开始以为是贪心+高精(直接python了),实际上拆位取模就可以
输出时候忘了取模wa了一发,绷不住了
py:
def swap_and_multiply(n, a, b):
a_list = list(a)
b_list = list(b)
for i in range(n):
if a_list[i] > b_list[i]:
a_list[i], b_list[i] = b_list[i], a_list[i]
a_swapped = int(''.join(a_list))
b_swapped = int(''.join(b_list))
return a_swapped * b_swapped
n = int(input())
a = input()
b = input()
result = swap_and_multiply(n, a, b)
print(result%998244353)
拆位取模,实际上不需要开__int128,习惯写法():
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<cmath>
#include<vector>
#define ll long long
#define li __int128
using namespace std;
string a,b;
inline __int128 read(){
__int128 x=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9'){
if(ch=='-')
f=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9'){
x=x*10+ch-'0';
ch=getchar();
}
return x*f;
}
inline void print(__int128 x){
if(x<0){
putchar('-');
x=-x;
}
if(x>9)
print(x/10);
putchar(x%10+'0');
}
int main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int n;cin>>n;
cin>>a>>b;
for(int i=0;i<n;i++){
if(a[i]>b[i]){
swap(a[i],b[i]);
}
}
li num1=0,num2=0;
for(int i=0;i<n;i++){
num1=(num1*10+(a[i]-'0'))%998244353;
num2=(num2*10+(b[i]-'0'))%998244353;
}
print((num1*num2)%998244353);
return 0;
}
C.
简单数学,但要求逆元
算分子分母时忘记取模导致longlong炸了,换__int128才过,给我唐完了
#include<bits/stdc++.h>
#include<algorithm>
#define ll long long
#define li __int128
using namespace std;
const li mod = 998244353;
inline __int128 read(){
__int128 x=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9'){
if(ch=='-')
f=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9'){
x=x*10+ch-'0';
ch=getchar();
}
return x*f;
}
inline void print(__int128 x){
if(x<0){
putchar('-');
x=-x;
}
if(x>9)
print(x/10);
putchar(x%10+'0');
}
// 快速幂求逆元
li pow_mod(li a, li b, li p){
li ans = 1;
while(b){
if(b & 1) ans = (ans * a) % p;
a = (a * a) % p;
b >>= 1;
}
return ans;
}
li inv(li a){
return pow_mod(a, mod-2, mod);
}
signed main(){
int T;cin>>T;
while(T--){
li m,a,b,c;
m=read(),a=read(),b=read(),c=read();
li q = (m-1)*3*b+c+a*(m*m-3*m+2);
li p = m*m;
if(q%p==0){
print(q/p);
cout<<'\n';
}
else{
li gcd = __gcd(q,p);
q/=gcd,p/=gcd;
print(((q%mod)*(inv(p)%mod))%mod);
cout<<'\n';
}
}
}
D:
打表找规律,发现x位置处帕鲁的工号是x对应的二进制数位进行反转
比如n=4时候,3=0011,反转后的1100=12,则x=3位置处工号为12;
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<cmath>
#include<vector>
#include<bitset>
#define ll long long
#define li __int128
using namespace std;
inline __int128 read(){
__int128 x=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9'){
if(ch=='-')
f=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9'){
x=x*10+ch-'0';
ch=getchar();
}
return x*f;
}
inline void print(__int128 x){
if(x<0){
putchar('-');
x=-x;
}
if(x>9)
print(x/10);
putchar(x%10+'0');
}
li qpow(li a, li b){
li ans = 1;
while(b){
if(b & 1) ans = (ans * a);
a = (a * a);
b >>= 1;
}
return ans;
}
int main(){
li n,m;n=read(),m=read();
while(m--){
li x;x=read();
bitset<100>bi(x);
li sum=0;
for(li i=0;i<n;i++){
if(bi[i]){
sum+=qpow(li(2),n-i-1);
}
}
print(sum);cout<<'\n';
}
return 0;
}