2018年浙江省大学生程序设计竞赛

在这里插入图片描述

A - Peak

看一下首次开始非单增的位置是否是单调递减即可

code:

#include<bits/stdc++.h>
#define int long long
#define endl '\n'

using namespace std;

const int N = 1e5 + 7;
int n;
int a[N];

void solve(){
    cin >> n;
    for(int i = 0;i < n;i ++) cin >> a[i];
    int flag = 0;
    int pos = 0;
    for(int i = 1;i < n;i ++){
         if(a[i] > a[i - 1]) flag = 1;
         else{
             pos = i;
             break;
         }
    } 
    if(!pos || !flag){
        cout << "No" << endl;
        return;
    }
    for(int i = pos;i < n;i ++){
        if(a[i] >= a[i - 1]){
            cout << "No" << endl;
            return;
        }
    }
    cout << "Yes" << endl;
} 

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr),cout.tie(nullptr);
    int _; cin >> _;
    while(_ --){
        solve();
    }
    return 0;
}

B - King of Karaoke

看差值有多少相同的即答案

code:

#include<bits/stdc++.h>
#define int long long
#define endl '\n'

using namespace std;

const int N = 1e5 + 7;
int n,k;
int a[N],b[N];

void solve(){
    cin >> n;
    for(int i = 0;i < n;i ++) cin >> a[i];
    for(int i = 0;i < n;i ++) cin >> b[i];
    map<int,int> mp;
    for(int i = 0;i < n;i ++){
        int cnt = a[i] - b[i];
        mp[cnt] ++;
    }
    int mx = -1;
    for(auto x : mp){
        mx = max(mx,x.second);
    }
    cout << mx << endl;
} 

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr),cout.tie(nullptr);
    int _; cin >> _;
    while(_ --){
        solve();
    }
    return 0;
}

J - CONTINUE…?

由题可知 g1 + g3 = g2 + g4
所以 sum 要整除 2
又可发现 长度为偶数时 每四个 i , i + 1 , i + 2 , i + 3 i,i + 1,i + 2,i + 3 i,i+1,i+2,i+3可以按 i + i + 3 = i + 1 + i + 2 i + i + 3 = i + 1 + i + 2 i+i+3=i+1+i+2来分组
长度为奇数时 先通过 i = 1 , i = n − 1 , i = n i =1,i = n - 1,i = n i=1,i=n1,i=n来分配 然后又得到一个偶数序列
按男女分配即可 并且可以发现 长度不能整除 4 的话依旧不符合

code:

#include<bits/stdc++.h>
#define int long long
#define endl '\n'

using namespace std;

int n;
string s;

void solve(){
    cin >> n;
    cin >> s; s = "?" + s;
    int sum = (n * n + n) / 2;
    if(sum % 2){
        cout << -1 << endl;
        return;
    }
    vector<int> st(n + 1,0);
    if(n & 1){
        if((n - 3) % 4){
            cout << -1 << endl;
            return;
        }
        if(s[1] == '1') st[1] = 3;
        else st[1] = 1;
        if(s[n - 1] == '1') st[n - 1] = 3;
        else st[n - 1] = 1;
        if(s[n] == '1') st[n] = 4;
        else st[n] = 2;
        for(int i = 2;i <= n - 2;i += 4){
            if(s[i] == '1') st[i] = 3;
            else st[i] = 1;
            if(s[i + 3] == '1') st[i + 3] = 3;
            else st[i + 3] = 1;
            if(s[i + 1] == '1') st[i + 1] = 4;
            else st[i + 1] = 2;
            if(s[i + 2] == '1') st[i + 2] = 4;
            else st[i + 2] = 2;
        }
    } else{
        if(n % 4){
            cout << -1 << endl;
            return;
        }
        for(int i = 1;i <= n;i += 4){
            if(s[i] == '1') st[i] = 3;
            else st[i] = 1;
            if(s[i + 3] == '1') st[i + 3] = 3;
            else st[i + 3] = 1;
            if(s[i + 1] == '1') st[i + 1] = 4;
            else st[i + 1] = 2;
            if(s[i + 2] == '1') st[i + 2] = 4;
            else st[i + 2] = 2;
        }
    }
    for(int i = 1;i <= n;i ++) cout << st[i];
    cout << endl;
} 

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr),cout.tie(nullptr);
    int _; cin >> _;
    while(_ --){
        solve();
    }
    return 0;
}

K - Mahjong Sorting

如果只有 1 张牌 那么答案为 3 * m
否则看有无白板 按有无白板和白板的位置去计算即可

code:

#include<bits/stdc++.h>
#define int long long
#define endl '\n'

using namespace std;

struct node{
    char s;
    int val = -1;
};

int n,m;
const int N = 1e5 + 7;
node a[N];

void solve(){
    cin >> n >> m;
    int pos = -1;
    for(int i = 0;i < n;i ++){
        cin >> a[i].s;
        if(a[i].s != 'W') cin >> a[i].val;
        else pos = i;
    }
    if(n == 1){
        cout << 3 * m << endl;
        return;
    }
    map<char,int> mp;
    mp['C'] = 0,mp['B'] = 1,mp['D'] = 2;
    if(pos == 0){
        cout << mp[a[pos + 1].s] * m + a[pos + 1].val - 1 << endl;
        return;
    }
    int flag = 0;
    int cnt = 0;
    for(int i = 1;i < n;i ++){
        if(i != pos){
            if(a[i].s == a[i - 1 - cnt].s){
                if(a[i].val < a[i - 1 - cnt].val){
                    flag = 1;
                    break;
                }
            } else{
                if((a[i].s == 'C' && a[i - 1 - cnt].s == 'D') || (a[i].s == 'C' && a[i - 1 - cnt].s == 'B') || (a[i].s == 'B' && a[i - 1 - cnt].s == 'D')){ 
                    flag = 1;
                    break;
                }
            }
            if(cnt) cnt = 0;
        } else{
            cnt ++;
        }
    }
    if(flag){
        cout << 1 << endl;
        return;
    }
    if(pos == -1){
        cout << 3 * m - (n - 1) << endl;
        return;
    }
    int l,r;
    if(pos == n - 1) r = 3 * m + 1;
    else r = mp[a[pos + 1].s] * m + a[pos + 1].val;
    l = mp[a[pos - 1].s] * m + a[pos - 1].val;
    int ans = r - l - 1;
    if(pos == 1) ans ++;
    cout << ans << endl;
} 

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr),cout.tie(nullptr);
    int _; cin >> _;
    while(_ --){
        solve();
    }
    return 0;
}

L - Doki Doki Literature Club

按要求模拟计算输出即可

code:

#include<bits/stdc++.h>
#define int long long
#define endl '\n'

using namespace std;

struct node{
    string s;
    int val;
    bool operator < (const node &sb){
        if(val == sb.val) return s < sb.s;
        return val > sb.val;
    } 
};

const int N = 1e5 + 7;
node a[N];
int n,m;

void solve(){
    cin >> n >> m;
    for(int i = 0;i < n;i ++){
        cin >> a[i].s;
        cin >> a[i].val;
    }
    sort(a,a + n);
    vector<string> v;
    int ans = 0;
    for(int i = 0;i < m;i ++){
        ans += a[i].val * (m - i);
        v.push_back(a[i].s); 
    }
    cout << ans;
    for(auto x : v) cout << " " << x;
    cout << endl; 
} 

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr),cout.tie(nullptr);
    int _; cin >> _;
    while(_ --){
        solve();
    }
    return 0;
}

M - Lucky 7

a i + k a_i + k ai+k能不能整除 7 7 7

code:

#include<bits/stdc++.h>
#define int long long
#define endl '\n'

using namespace std;

const int N = 1e5 + 7;
int n,k;
int a[N];

void solve(){
    cin >> n >> k;
    int flag = 0;
    for(int i = 0;i < n;i ++){
        int x; cin >> x;
        int cnt = x + k;
        if(cnt % 7 == 0) flag = 1;
    }
    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
} 

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr),cout.tie(nullptr);
    int _; cin >> _;
    while(_ --){
        solve();
    }
    return 0;
}
  • 57
    点赞
  • 25
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值