A - Pawn on a Grid
题意:就是让你求出这个n行n列中‘#’的个数
思路:直接枚举就行了。
代码:
/*
by:lwq132lwq
*/
#include<bits/stdc++.h>
using namespace std;
#define IO ios::sync_with_stdio(false);cin.tie(0);
#define ll long long
#define dd double
#define re register
#define il inline
#define pb push_back
#define fr frist
#define sc second
template <class T> void read(T &x){
x=0;int f=0;char ch=getchar();
while(ch<'0'||ch>'9'){f|=(ch=='-');ch=getchar();}
while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
x=f?-x:x;return ;
}
bool cmp(int x,int y){return x>y;}
dd ddabs(double x){if(x<0) return -x;else return x;}
int gcd(int a, int b){return b ? gcd(b,a%b):a;}
//const int maxn=
int n,m;
int ans;
int main()
{
read(n);read(m);
for(int i=1;i<=n;i++)
{
string s;
cin>>s;
for(int j=0;j<m;j++)
{
if(s[j]=='#') ans++;
}
}
cout<<ans;
return 0;
}
B - Inverse Prefix Sum
题意:给我们一个有n个数的a[n]数组,让我们构造一个序列,使得在这个构造的序列中,前k个数的和等于a[k]。
思路:直接利用差分的思想
代码:
/*
by:lwq132lwq
*/
#include<bits/stdc++.h>
using namespace std;
#define IO ios::sync_with_stdio(false);cin.tie(0);
#define int long long
#define dd double
#define re register
#define il inline
#define pb push_back
#define fr frist
#define sc second
template <class T> void read(T &x){
x=0;int f=0;char ch=getchar();
while(ch<'0'||ch>'9'){f|=(ch=='-');ch=getchar();}
while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
x=f?-x:x;return ;
}
bool cmp(int x,int y){return x>y;}
dd ddabs(double x){if(x<0) return -x;else return x;}
int gcd(int a, int b){return b ? gcd(b,a%b):a;}
//const int maxn=
int n;
int a[20];
signed main()
{
read(n);
for(int i=1;i<=n;i++) read(a[i]);
cout<<a[1]<<" ";
for(int i=2;i<=n;i++)
cout<<a[i]-a[i-1]<<" ";
return 0;
}
C - Extra Character
题意:给你两个字符串s和t,其中t是在s中插入一个字母形成的,在t中求出插入那个字母的位置
思路:直接按位置比较两个字符串,当发现第一次出现t[i]!=s[i]的时候,此时的i就是我们要找的那个m的位置。
/*
by:lwq132lwq
*/
#include<bits/stdc++.h>
using namespace std;
#define IO ios::sync_with_stdio(false);cin.tie(0);
#define int long long
#define dd double
#define re register
#define il inline
#define pb push_back
#define fr frist
#define sc second
template <class T> void read(T &x){
x=0;int f=0;char ch=getchar();
while(ch<'0'||ch>'9'){f|=(ch=='-');ch=getchar();}
while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
x=f?-x:x;return ;
}
bool cmp(int x,int y){return x>y;}
dd ddabs(double x){if(x<0) return -x;else return x;}
int gcd(int a, int b){return b ? gcd(b,a%b):a;}
//const int maxn=
signed main()
{
string s,t;
cin>>s>>t;
int len=t.size();
for(int i=0;i<len;i++)
{
if(s[i]!=t[i])
{
cout<<i+1;
return 0;
}
}
return 0;
}
D - Factorial and Multiple
题意:给你一个k,求n,使得n!是k的整数倍。
思路:先利用质因数分解把k给分解开,我们用结构体存储质数及其个数。然后我们利用二分的思想去检查,检查是否实现,最终得到答案。
代码
/*
by:lwq132lwq
*/
#include<bits/stdc++.h>
using namespace std;
#define IO ios::sync_with_stdio(false);cin.tie(0);
#define int long long
#define dd double
#define re register
#define il inline
#define pb push_back
#define fr frist
#define sc second
template <class T> void read(T &x){
x=0;int f=0;char ch=getchar();
while(ch<'0'||ch>'9'){f|=(ch=='-');ch=getchar();}
while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
x=f?-x:x;return ;
}
bool cmp(int x,int y){return x>y;}
dd ddabs(double x){if(x<0) return -x;else return x;}
int gcd(int a, int b){return b ? gcd(b,a%b):a;}
const int maxn=1e8;
int n,ans,cnt;
struct note{int f,s;}c[maxn];
bool ask(int a)
{
for(int i=1;i<=cnt;i++)
{
int t=0,q=c[i].f;
while(q<=a)
{
t+=a/q;
q*=c[i].f;
}
if(t<c[i].s) return false;
}
return true;
}
signed main()
{
read(n);
int l=n;
for(int i=2;i*i<=l;i++)
{
if(l%i==0)
{
int tot=0;
while(l%i==0)
{
tot++;
l/=i;
}
c[++cnt].f=i;
c[cnt].s=tot;
}
}
if(l>1)
c[++cnt].f=l,c[cnt].s=1;
int L=0,R=n+5;
while(L<R)
{
int x=L+R>>1;
if(ask(x))R=x;
else L=x+1;
}
cout<<L;
return 0;
}
E - Critical Hit
题意:一个怪物的血量为n,每次攻击让他掉两滴血的概率是,掉一滴血的概率是
,求出让怪物的血变为零或者更低的时候的攻击次数的期望。
思路:这道题是期望初学的一道简单题,设f[i]是让怪物掉i滴血的期望,f[i]=( f[i-2]*+f[i-1]*
)+1,利用这个思路转移即可。(注意:这里要用逆元)
代码:
/*
by:lwq132lwq
*/
#include<bits/stdc++.h>
using namespace std;
#define IO ios::sync_with_stdio(false);cin.tie(0);
#define int long long
#define dd double
#define re register
#define il inline
#define pb push_back
#define fr frist
#define sc second
template <class T> void read(T &x){
x=0;int f=0;char ch=getchar();
while(ch<'0'||ch>'9'){f|=(ch=='-');ch=getchar();}
while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
x=f?-x:x;return ;
}
bool cmp(int x,int y){return x>y;}
dd ddabs(double x){if(x<0) return -x;else return x;}
int gcd(int a, int b){return b ? gcd(b,a%b):a;}
const int mod=998244353,maxn=5e5+10;
int qkm(int a,int b)
{
int res=1;
while(b)
{
if(b%2) res=(res*a)%mod;
a=(a*a)%mod;
b>>=1;
}
return res;
}
int f[maxn],n,q,d=100;
signed main()
{
read(n);read(q);
int GCD=gcd(q,d);
d/=GCD,q/=GCD;
int tru=qkm(d,mod-2)*q%mod,fal=qkm(d,mod-2)*(d-q)%mod;
f[1]=1;
for(int i=2;i<=n;i++) f[i]=(f[i-2]*tru+f[i-1]*fal+1)%mod;
cout<<f[n];
return 0;
}