SDUT 2021 Spring Team Contest--- 2(Kattis)

74 篇文章 12 订阅
48 篇文章 0 订阅

G - Physical Music

题目链接

答案:

#include <iostream>
#include<bits/stdc++.h>
#define ll long long
#define PII pair<int,int>
#define pb push_back
#define x first
#define y second
#define INF 0x3f3f3f3f
const int N = 1e5 + 10;
using namespace std;

vector<int>vp;
int dp[N];
int tot=0;

int main()
{
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        vp.clear();
        int minn=INF;
        for(int i=1;i<=n;i++) cin>>dp[i];
        for(int i=n;i>=1;i--){
            if(dp[i]>minn){
                vp.pb(dp[i]);
            }
            minn=min(minn,dp[i]);
        }
        cout<<(int)vp.size()<<endl;
        sort(vp.begin(),vp.end(),greater<int>());
        for(int i=(int)vp.size()-1;i>=0;i--){
            cout<<vp[i]<<endl;
        }
    }
    return 0;
}

I - Stand on Zanzibar

题目链接

答案:

#include <iostream>
#include<bits/stdc++.h>
#define ll long long
#define PII pair<int,int>
#define pb push_back
#define x first
#define y second
const int N = 2e5 + 10;
using namespace std;

int main()
{
    int t;
    cin>>t;
    while(t--){
        int k;
        int p;
        int tot=0;
        cin>>p;
        if(!p){
            cout<<tot<<endl;;
            break;
        }
        while(cin>>k){
            if(!k) {
                cout<<tot<<endl;;
                break;
            }
            else{
                if(p*2<k) tot+=k-2*p;
                p=k;
            }
        }
    }
    return 0;
}

J - The King’s Walk

题目链接

答案:

#include <memory.h>
#include <algorithm>
#include <stdio.h>
#include <math.h>
using namespace std;
const int N = 10100;
#define ll long long
int f[N][N];
const int mod= 5318008;
void fx(int s,int t,int p,int n){
    memset(f,0,sizeof(f)
    );
    f[0][s]=1;
    for(int i=1;i<=p;i++){
        for(int j=1;j<=n;j++){
            f[i][j]=f[i-1][j]%mod;
            if(j<n) f[i][j]+=f[i-1][j+1];
            f[i][j]%=mod;
            if(j>1) f[i][j]+=f[i-1][j-1];
            f[i][j]%=mod;
        }
    }
    printf("%d\n",f[p][t]);
}
int main(){
    int n,u,x1,x2,y1,y2;
    scanf("%d",&u);
    while(u--){
        scanf("%d %d %d %d %d",&n,&x1,&y1,&x2,&y2);
         int p=abs(x1-x2),q=abs(y1-y2);
         if(q<p){

            fx(y1,y2,p,n);
         }
         else {
            fx(x1,x2,q,n);
         }
    }
    return 0;
}

L - Wipe Your Whiteboards

题目链接

答案:

#include <iostream>
#include<bits/stdc++.h>
#define ll long long
#define PII pair<int,int>
#define pb push_back
#define x first
#define y second
#define INF 0x3f3f3f3f
const int N = 1e5 + 10;
const int mod= 5318008;
using namespace std;

ll a,b;
ll r,s,q;

ll extend_gcd(ll a,ll b,ll &x,ll &y){
    //if(!a||!b) return -1;
    if(!b){
        x=1;
        y=0;
        return a;
    }
//    ll d=extend_gcd(b,a%b,x,y);
//    ll temp=x;
//    x=y;
//    y=temp-(a/b)*y;
    ll d=extend_gcd(b,a%b,y,x);
    y-=(a/b)*x;
    return d;
}

int main(){
    ios::sync_with_stdio(0);
    ll t;
    cin>>t;
    while(t--){
        cin>>r>>s>>q;
        ll gcd=extend_gcd(r,-s,a,b);
        b=-b;
        ll A=(q/gcd)*a;
        ll B=(q/gcd)*b;
//        cout<<A<<" "<<B<<endl;
        //ll temp=q/gcd;
        ll xx=s/gcd;
        ll yy=r/gcd;
        while(A>=1&&B>=1){
            A+=xx;
            B-=yy;
        }
//        cout<<A<<" "<<B<<endl;
        while(A<1||B<1){
            A-=xx;
            B+=yy;
        }
        cout<<A<<" "<<B<<endl;
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值