A.夹娃娃
题意:
题解:
AC代码
/* Author:zzugzx Lang:C++ Blog:blog.csdn.net/qq_43756519 */ #include<bits/stdc++.h> using namespace std; #define fi first #define se second #define pb push_back #define mp make_pair #define all(x) (x).begin(),(x).end() #define endl '\n' #define SZ(x) (int)x.size() typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int mod=1e9+7; //const int mod=998244353; const double eps = 1e-10; const double pi=acos(-1.0); const int maxn=1e6+10; const ll inf=0x3f3f3f3f; const int dir[8][2]={{0,1},{1,0},{0,-1},{-1,0},{1,1},{1,-1},{-1,1},{-1,-1}}; int a[maxn],sum[maxn]; int main() { ios::sync_with_stdio(false); cin.tie(0);cout.tie(0); //freopen("in.txt","r",stdin); //freopen("out.txt","w",stdout); int n,k;cin>>n>>k; for(int i=1;i<=n;i++)cin>>a[i],sum[i]=sum[i-1]+a[i]; while(k--){ int l,r; cin>>l>>r; cout<<sum[r]-sum[l-1]<<endl; } return 0; }
B.莫的难题
题意:
题解:
AC代码
/* Author:zzugzx Lang:C++ Blog:blog.csdn.net/qq_43756519 */ #include<bits/stdc++.h> using namespace std; #define fi first #define se second #define pb push_back #define mp make_pair #define all(x) (x).begin(),(x).end() #define endl '\n' #define SZ(x) (int)x.size() typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int mod=1e9+7; //const int mod=998244353; const double eps = 1e-10; const double pi=acos(-1.0); const int maxn=1e6+10; const ll inf=0x3f3f3f3f; const int dir[8][2]={{0,1},{1,0},{0,-1},{-1,0},{1,1},{1,-1},{-1,1},{-1,-1}}; ll fact[maxn],inv1[maxn]; ll Pow(ll a, ll b){ ll ans = 1; while(b > 0){ if(b & 1){ ans = ans * a % mod; } a = a * a % mod; b >>= 1; } return ans; } //逆元 ll inv(ll b){ return Pow(b,mod-2)%mod; } ll C(ll n,ll m){ if(m>n||n<0||m<0)return 0; if(m==0||m==n) return 1; ll res=(fact[n]*inv1[m]%mod*inv1[n-m])%mod; return res; } void init() { fact[0] = 1; for (int i = 1; i < maxn; i++) { fact[i] = fact[i - 1] * i %mod; } inv1[maxn - 1] = Pow(fact[maxn - 1], mod - 2); for (int i = maxn - 2; i >= 0; i--) { inv1[i] = inv1[i + 1] * (i + 1) %mod; } } int a[]={1,2,3,5,9}; int main() { ios::sync_with_stdio(false); cin.tie(0);cout.tie(0); //freopen("in.txt","r",stdin); //freopen("out.txt","w",stdout); int _; cin>>_; init(); while(_--){ ll n,m; cin>>n>>m; ll x=C(n,m); stack<int> s; while(x>0){ x--; s.push(x%5); x/=5; } while(s.size())cout<<a[s.top()],s.pop(); cout<<endl; } return 0; }
C. 不平衡数组
题意:
题解:
AC代码
/* Author:zzugzx Lang:C++ Blog:blog.csdn.net/qq_43756519 */ #include<bits/stdc++.h> using namespace std; #define fi first #define se second #define pb push_back #define mp make_pair #define all(x) (x).begin(),(x).end() #define endl '\n' #define SZ(x) (int)x.size() typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int mod=911451407; //const int mod=998244353; const double eps = 1e-10; const double pi=acos(-1.0); const int maxn=1e6+10; const ll inf=0x3f3f3f3f; const int dir[8][2]={{0,1},{1,0},{0,-1},{-1,0},{1,1},{1,-1},{-1,1},{-1,-1}}; ll n,ans=1e18; ll a[maxn],b[maxn]; ll dp[maxn][2]; int main() { ios::sync_with_stdio(false); cin.tie(0);cout.tie(0); //freopen("in.txt","r",stdin); //freopen("out.txt","w",stdout); cin>>n; for(int i=1;i<=n;i++)cin>>a[i]>>b[i]; for(int i=1;i<=n;i++)dp[i][1]=dp[i][0]=1e18; dp[0][0]=0; for(int i=1;i<=n;i++){ if(a[i]+1!=a[i-1])dp[i][1]=min(dp[i][1],dp[i-1][0]+b[i]); if(a[i]!=a[i-1]+1)dp[i][0]=min(dp[i][0],dp[i-1][1]); if(a[i]!=a[i-1])dp[i][0]=min(dp[i][0],dp[i-1][0]); if(a[i]+1!=a[i-1]+1)dp[i][1]=min(dp[i][1],dp[i-1][1]+b[i]); } cout<<min(dp[n][1],dp[n][0]); return 0; }
D. 数列统计
题意:
题解:
AC代码
/* Author:zzugzx Lang:C++ Blog:blog.csdn.net/qq_43756519 */ #include<bits/stdc++.h> using namespace std; #define fi first #define se second #define pb push_back #define mp make_pair #define all(x) (x).begin(),(x).end() #define endl '\n' #define SZ(x) (int)x.size() typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int mod=911451407; //const int mod=998244353; const double eps = 1e-10; const double pi=acos(-1.0); const int maxn=2e6+10; const ll inf=0x3f3f3f3f; const int dir[8][2]={{0,1},{1,0},{0,-1},{-1,0},{1,1},{1,-1},{-1,1},{-1,-1}}; ll fact[maxn],inv1[maxn]; ll Pow(ll a, ll b){ ll ans = 1; while(b > 0){ if(b & 1){ ans = ans * a % mod; } a = a * a % mod; b >>= 1; } return ans; } //逆元 ll inv(ll b){ return Pow(b,mod-2)%mod; } ll C(ll n,ll m){ if(m>n||n<0||m<0)return 0; if(m==0||m==n) return 1; ll res=(fact[n]*inv1[m]%mod*inv1[n-m])%mod; return res; } void init() { fact[0] = 1; for (int i = 1; i < maxn; i++) { fact[i] = fact[i - 1] * i %mod; } inv1[maxn - 1] = Pow(fact[maxn - 1], mod - 2); for (int i = maxn - 2; i >= 0; i--) { inv1[i] = inv1[i + 1] * (i + 1) %mod; } } int main() { ios::sync_with_stdio(false); cin.tie(0);cout.tie(0); //freopen("in.txt","r",stdin); //freopen("out.txt","w",stdout); int _; init(); while(cin>>_){ while(_--){ ll l,x; cin>>l>>x; cout<<C(l+x-2,x-1)<<endl; } } return 0; }