目录
。。。。B题还不会,会了就补QAQ。。。
A - Multiplication Dilemma
题目链接https://codeforces.com/gym/101972/problem/A
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100;
int a[maxn],b[maxn];
std::vector<pair<int,int> > v;
int main(int argc, char const *argv[])
{
int t;
cin >> t;
while(t--){
int x,y;
memset(a,0,sizeof a);
memset(b,0,sizeof b);
v.clear();
cin >> x >> y;
int n = x , m = y;
int cnt1 = 0 , cnt2 = 0;
while(n){
cnt1 ++;
a[cnt1] = n % 10;
a[cnt1] *= pow(10,cnt1-1);
n /= 10;
}
while(m){
cnt2 ++;
b[cnt2] = m % 10;
b[cnt2] *= pow(10,cnt2 - 1);
m /= 10;
}
for(int i = 1;i <= 10;i ++){
if(a[i] == 0) continue;
for(int j = 1;j <= 10;j ++){
if(b[j] == 0) continue;
v.push_back(make_pair(a[i],b[j]));
}
}
for(int i = 0;i < v.size();i ++){
if(i == v.size() - 1){
cout << v[i].first << " x " << v[i].second << endl;
}
else
cout << v[i].first << " x " << v[i].second << " + " ;
}
}
return 0;
}
B - Updating the Tree
题目链接https://codeforces.com/gym/101972/problem/B
C - Shortest Path!
题目链接https://codeforces.com/gym/101972/problem/C
/**Today you do things people will not do,
tomorrow you will do things people can not do.**/
#include<bits/stdc++.h>
#define ll long long
#define lson l,m,cnt<<1
#define rson m+1,r,cnt<<1|1
#define mem(a,b) memset(a,b,sizeof(a))
//priority_queue <int,vector<int>,greater<int> > Q;//优先队列递增
//priority_queue<int>Q;//递减
using namespace std;
const int maxn = 15;
const int mod = 1e8;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-6;
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
double a,b,c,x;
scanf("%lf%lf%lf%lf",&a,&b,&c,&x);
double s=sqrt((a*a)+(b+2*c)*(b+2*c));
double d=b/100*x;
double e=a/100*x;
s+=sqrt(d*d+e*e)+sqrt((b-d+2*c)*(b-d+2*c)+(a-e)*(a-e));
printf("%.9lf\n",s);
}
}
D - Wooden Fence
题目链接https://codeforces.com/gym/101972/problem/D
/**Today you do things people will not do,
tomorrow you will do things people can not do.**/
#include<bits/stdc++.h>
#define ll long long
#define lson l,m,cnt<<1
#define rson m+1,r,cnt<<1|1
#define mem(a,b) memset(a,b,sizeof(a))
//priority_queue <int,vector<int>,greater<int> > Q;//优先队列递增
//priority_queue<int>Q;//递减
using namespace std;
const int maxn = 15;
const int mod = 1e8;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-6;
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n,a,b;
scanf("%d%d%d",&n,&a,&b);
int ans=n/2;
if(a>=ans+1&&b>=ans)
printf("YES\n");
else
printf("NO\n");
}
}
E - Stupid Submissions
题目链接https://codeforces.com/gym/101972/problem/E
/**Today you do things people will not do,
tomorrow you will do things people can not do.**/
#include<bits/stdc++.h>
#define ll long long
#define lson l,m,cnt<<1
#define rson m+1,r,cnt<<1|1
#define mem(a,b) memset(a,b,sizeof(a))
//priority_queue <int,vector<int>,greater<int> > Q;//优先队列递增
//priority_queue<int>Q;//递减
using namespace std;
const int maxn = 1e4+5;
const int mod = 1e8;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-6;
int s[maxn];
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n,m,k,ans=0;
scanf("%d %d %d",&n,&m,&k);
char c[10];
for(int i=1;i<=n;i++)
{
scanf("%s",c);
if(c[0]=='S') s[i]=0;
else s[i]=1;
}
for(int i=1;i<=m;i++)
{
scanf("%s",c);
if(c[0]=='W')
{
int a;
scanf("%d",&a);
if(s[a]==0&&a<=k) ans++;
k=max(a,k);
}
else if(c[0]=='A') k=n;
}
printf("%d\n",ans);
}
}
F - I'm Bored!
题目链接https://codeforces.com/gym/101972/problem/F
/**Today you do things people will not do,
tomorrow you will do things people can not do.**/
#include<bits/stdc++.h>
#define ll long long
#define lson l,m,cnt<<1
#define rson m+1,r,cnt<<1|1
#define mem(a,b) memset(a,b,sizeof(a))
//priority_queue <int,vector<int>,greater<int> > Q;//优先队列递增
//priority_queue<int>Q;//递减
using namespace std;
const int maxn = 35;
const int mod = 1e8;
const ll INF = 1e18;
const double PI = acos(-1.0);
const double eps = 1e-6;
ll a[maxn];
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
ll n1=0,n2=0,sum=0;
ll minn=INF;
for(int i=1;i<=26;i++)
{
scanf("%lld",&a[i]);
if(a[i]==1) n1++;
if(a[i]>=2)
{
n2++;
minn=min(minn,a[i]/2);
}
}
ll ans=n2*2,res;
if(n1>0) ans++,res=min(minn,n1);
else res=minn;
if(minn==INF) res=n1;
printf("%lld %lld\n",ans,res);
}
}
G - Minimax
题目链接https://codeforces.com/gym/101972/problem/G
/**Today you do things people will not do,
tomorrow you will do things people can not do.**/
#include<bits/stdc++.h>
#define ll long long
#define lson l,m,cnt<<1
#define rson m+1,r,cnt<<1|1
#define mem(a,b) memset(a,b,sizeof(a))
//priority_queue <int,vector<int>,greater<int> > Q;//优先队列递增
//priority_queue<int>Q;//递减
using namespace std;
const int maxn = 505;
const int mod = 1e8;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-6;
int a[maxn][maxn], n, m;
int dp1[maxn][maxn], dp2[maxn][maxn], dp3[maxn][maxn], dp4[maxn][maxn];
void init()
{
memset(dp1, 0, sizeof(dp1));
memset(dp2, 0, sizeof(dp2));
memset(dp3, 0, sizeof(dp3));
memset(dp4, 0, sizeof(dp4));
memset(a, 0, sizeof(a));
}
void Getmax()
{
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= m; j++)
{
int maxx = max(dp1[i - 1][j], dp1[i][j - 1]);
dp1[i][j] = max(dp1[i][j], maxx);
}
}
for (int i = n; i >= 1; i--)
{
for (int j = 1; j <= m; j++)
{
int maxx = max(dp2[i + 1][j], dp2[i][j - 1]);
dp2[i][j] = max(dp2[i][j], maxx);
}
}
for (int i = 1; i <= n; i++)
{
for (int j = m; j >= 1; j--)
{
int maxx = max(dp3[i - 1][j], dp3[i][j + 1]);
dp3[i][j] = max(dp3[i][j], maxx);
}
}
for (int i = n; i >= 1; i--)
{
for (int j = m; j >= 1; j--)
{
int maxx = max(dp4[i + 1][j], dp4[i][j + 1]);
dp4[i][j] = max(dp4[i][j], maxx);
}
}
}
int max4(int a, int b, int c, int d, int e)
{
a = max(a, b);
a = max(a, c);
a = max(a, d);
a = max(a, e);
return a;
}
int min4(int a, int b, int c, int d, int e)
{
a = min(a, b);
a = min(a, c);
a = min(a, d);
a = min(a, e);
return a;
}
int main()
{
int t;
scanf("%d", &t);
while (t--)
{
int ans = 0x3f3f3f3f;
init();
scanf("%d %d", &n, &m);
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= m; j++)
{
scanf("%d", &a[i][j]);
dp1[i][j] = a[i][j];
dp2[i][j] = a[i][j];
dp3[i][j] = a[i][j];
dp4[i][j] = a[i][j];
}
}
Getmax();
for (int i = 2; i < n; i++)
{
for (int j = 2; j < m; j++)
{
int maxx = -1;
int minn = 0x3f3f3f3f;
maxx = max4(maxx, dp1[i - 1][j - 1], dp2[i + 1][j - 1], dp3[i - 1][j + 1], dp4[i + 1][j + 1]);
minn = min4(minn, dp1[i - 1][j - 1], dp2[i + 1][j - 1], dp3[i - 1][j + 1], dp4[i + 1][j + 1]);
ans = min(ans, maxx - minn);
}
}
printf("%d\n", ans);
}
}
H - Beautiful Substrings
题目链接https://codeforces.com/gym/101972/problem/H
/**Today you do things people will not do,
tomorrow you will do things people can not do.**/
#include<bits/stdc++.h>
#define ll long long
#define lson l,m,cnt<<1
#define rson m+1,r,cnt<<1|1
#define mem(a,b) memset(a,b,sizeof(a))
//priority_queue <int,vector<int>,greater<int> > Q;//优先队列递增
//priority_queue<int>Q;//递减
using namespace std;
const int maxn = 1e5 + 5;
const int mod = 1e8;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-6;
char s1[maxn], s2[maxn];
int vis1[30][30], vis2[30];
int main()
{
int t;
scanf("%d", &t);
while (t--)
{
int n1, n2, k;
memset(vis1, 0, sizeof(vis1));
memset(vis2, 0, sizeof(vis2));
scanf("%d %d %d", &n1, &n2, &k);
scanf("%s %s", s1 + 1, s2 + 1);
for (int i = 1; i + k - 1 <= n1; i++) vis1[s1[i] - 'a'][s1[i + k - 1] - 'a'] = 1;
ll ans = 0;
for (int i = 1; i <= n2; i++)
{
int u = s2[i] - 'a';
vis2[u]++;
for (int j = 0; j <= 26; j++)
{
if (vis1[j][u]) ans += vis2[j];
}
}
printf("%lld\n", ans);
}
}
I - Secret Project
题目链接https://codeforces.com/gym/101972/problem/I
#include <bits/stdc++.h>
using namespace std;
const int mac = 1e5 + 10;
#define ll long long
const int M = 1e9 + 7;
const int N = 1e5 + 7;
ll fac[N]={1,1},inv[N]={1,1},f[N]={1,1};
ll C(ll a,ll b){
if(b>a)return 0;
return fac[a]*inv[b]%M*inv[a-b]%M;
}
void init(){//快速计算阶乘的逆元
for(int i=2;i<N;i++){
fac[i]=fac[i-1]*i%M;
f[i]=(M-M/i)*f[M%i]%M;
inv[i]=inv[i-1]*f[i]%M;
}
}
int main()
{
int t;
ll n;
init();
scanf("%d", &t);
while (t--)
{
ll x,y;
cin >> x >> y;
cout << C(x,y-1) << " " << C(x-1,y-1) << endl;
}
return 0;
}
J - Even Numbers
题目链接https://codeforces.com/gym/101972/problem/J
#include <bits/stdc++.h>
using namespace std;
const int mac = 1e5 + 10;
#define ll long long
int a[mac];
int main()
{
int t;
ll n;
scanf("%d", &t);
while (t--)
{
int num = 0;
scanf("%lld", &n);
long long sum = n;
while (n) {
if (n & 1) num++;
n >>= 1;
}
cout << sum - 1ll * (1ll << num) + 1 << endl;
}
return 0;
}
K - Cyclic Shift
题目链接https://codeforces.com/gym/101972/problem/K
/**Today you do things people will not do,
tomorrow you will do things people can not do.**/
#include<bits/stdc++.h>
#define ll long long
#define lson l,m,cnt<<1
#define rson m+1,r,cnt<<1|1
#define mem(a,b) memset(a,b,sizeof(a))
//priority_queue <int,vector<int>,greater<int> > Q;//优先队列递增
//priority_queue<int>Q;//递减
using namespace std;
const int maxn = 15;
const int mod = 1e8;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-6;
vector<int> G;
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n;
scanf("%d",&n);
string a,b;
G.clear();
cin>>a>>b;
for(int i=0;i<n;i++)
{
if(a[i]!=b[i])
{
G.push_back(i);
}
}
int flag=1;
for(int i=0;i<G.size();i++)
{
G[i+1]=G[(i+1)%(G.size())];
if(b[G[i]]!=a[G[i+1]])
{
flag=0;
break;
}
}
if(flag==1) printf("YES\n");
else printf("NO\n");
}}