csust-8.5组队训练-Gym - 101972(三星题)

目录

 

A - Multiplication Dilemma

B - Updating the Tree

C - Shortest Path!

D - Wooden Fence

E - Stupid Submissions

F - I'm Bored!

G - Minimax

H - Beautiful Substrings

I - Secret Project

J - Even Numbers

K - Cyclic Shift


。。。。B题还不会,会了就补QAQ。。。

A - Multiplication Dilemma

 Gym - 101972A 

题目链接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

 Gym - 101972B 

题目链接https://codeforces.com/gym/101972/problem/B

C - Shortest Path!

 Gym - 101972C 

题目链接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

 Gym - 101972D 

题目链接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

 Gym - 101972E 

题目链接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!

 Gym - 101972F 

题目链接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

 Gym - 101972G 

题目链接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

 Gym - 101972H 

题目链接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

 Gym - 101972I 

题目链接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

 Gym - 101972J 

题目链接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

 Gym - 101972K 

题目链接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");
    }}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值