SDUT 2021 Spring Team Contest--- 23 (Kattis) 题解

48 篇文章 0 订阅
8 篇文章 0 订阅
本文汇总了多个编程竞赛的题目及解答,包括C题的密码难题、D题的灾难性停机时间分析、E题的娱乐盒优化、G题的哥布林花园守卫策略以及F题的软盘音乐播放问题。通过这些题目,展示了选手在解决复杂算法和逻辑问题上的技巧和方法。
摘要由CSDN通过智能技术生成

C - Cryptographer’s Conundrum

题目链接

答案

#include <iostream>
#include <algorithm>
#include<bits/stdc++.h>
#define ll long long
#define mem(a,b) memset(a,b,sizeof a)
#define ull unsigned long long
#define INF 0x3f3f3f3f3f3f3f3f
#define inf 0x3f3f3f3f
#define rep(i,a,b) for(auto i=a;i<=b;++i)
#define bep(i,a,b) for(auto i=a;i>=b;--i)
#define lowbit(x) x&(-x)
#define PII pair<int,int>
#define x first
#define y second
#define PLL pair<ll,ll>
#define PI acos(-1)
#define pb push_back
#define eb emplace_back
const double eps = 1e-6;
const int mod = 998244353;
const int MOD = 1e9 + 7;
const int N = 2e5 + 10;
const int M = 111;
int dx[]={-1, 0, 1, 0};
int dy[]={0, 1, 0, -1};
using namespace std;

inline void solve(){
    string s;
    cin>>s;
    int res=0;
    for(int i=0;i<s.size();i++){
        if(i%3==0) if(s[i]!='P') res++;
        if(i%3==1) if(s[i]!='E') res++;
        if(i%3==2) if(s[i]!='R') res++;
    }
    cout<<res<<endl;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}

D - Disastrous Downtime

题目链接

答案

#include <bits/stdc++.h>

#include <algorithm>
#include <iostream>
#define ll long long
#define mem(a, b) memset(a, b, sizeof a)
#define ull unsigned long long
#define INF 0x3f3f3f3f3f3f3f3f
#define inf 0x3f3f3f3f
#define rep(i, a, b) for (auto i = a; i <= b; ++i)
#define bep(i, a, b) for (auto i = a; i >= b; --i)
#define lowbit(x) x&(-x)
#define PII pair<int, int>
#define x first
#define y second
#define PLL pair<ll, ll>
#define PI acos(-1)
#define pb push_back
#define eb emplace_back
const double eps = 1e-6;
const int mod = 998244353;
const int MOD = 1e9 + 7;
const int N = 2e5 + 10;
const int M = 111;
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};
using namespace std;

map<int, int> mp;
struct node {
    int add;
    int data;
} a[N];

inline void solve() {
    int n, m;
    cin >> n >> m;
    int k;
    for (int i = 1; i <= n; i++) {
        cin >> k;
        if (!mp.count(k))
            mp[k] = 1;
        else
            mp[k]++;
    }
    int tot = 0;
    int sum = 0, maxx = -1;
    for (auto i : mp) {
        a[tot++] = {i.x, i.y};
    }
    for (int i = 0, j = 0; i < tot; i++) {
        for (; a[i].add - a[j].add >= 1000 && j < i; j++)  //
        {
            if (a[i].add - a[j].add < 1000) break;
            sum -= a[j].data;
        }
        sum += a[i].data;
        maxx = max(sum, maxx);
    }
    int ans = maxx / m;
    if (maxx % m != 0) ans++;
    cout << ans << "\n";
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}

E - Entertainment Box

题目链接

答案

#include <iostream>
#include <algorithm>
#include<bits/stdc++.h>
#define ll long long
#define mem(a,b) memset(a,b,sizeof a)
#define ull unsigned long long
#define INF 0x3f3f3f3f3f3f3f3f
#define inf 0x3f3f3f3f
#define rep(i,a,b) for(auto i=a;i<=b;++i)
#define bep(i,a,b) for(auto i=a;i>=b;--i)
#define lowbit(x) x&(-x)
#define PII pair<int,int>
#define x first
#define y second
#define PLL pair<ll,ll>
#define PI acos(-1)
#define pb push_back
#define eb emplace_back
const double eps = 1e-6;
const int mod = 998244353;
const int MOD = 1e9 + 7;
const int N = 2e5 + 10;
const int M = 111;
int dx[]={-1, 0, 1, 0};
int dy[]={0, 1, 0, -1};
using namespace std;

struct node{
    int x;
    int y;
    bool operator<(node &a){
        return y<a.y;
    }
}dp[N];

vector<int>vp;

inline void solve(){
    int n,k;
    cin>>n>>k;
    for(int i=1;i<=n;i++) cin>>dp[i].x>>dp[i].y;
    sort(dp+1,dp+1+n);
    for(int i=0;i<k;i++) vp.eb(0);
    int res=0;
    for(int i=1;i<=n;i++){
        auto pos=upper_bound(vp.begin(),vp.end(),dp[i].x);
        if(pos!=vp.begin()){
            vp.erase(pos-1);
            vp.eb(dp[i].y);
            res++;
        }
    }
    cout<<res<<endl;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}

G - Goblin Garden Guards

题目链接

答案

#include <iostream>
#include <algorithm>
#include<bits/stdc++.h>
#define ll long long
#define mem(a,b) memset(a,b,sizeof a)
#define ull unsigned long long
#define INF 0x3f3f3f3f3f3f3f3f
#define inf 0x3f3f3f3f
#define rep(i,a,b) for(auto i=a;i<=b;++i)
#define bep(i,a,b) for(auto i=a;i>=b;--i)
#define lowbit(x) x&(-x)
#define PII pair<int,int>
#define x first
#define y second
#define PLL pair<ll,ll>
#define PI acos(-1)
#define pb push_back
#define eb emplace_back
const double eps = 1e-6;
const int mod = 998244353;
const int MOD = 1e9 + 7;
const int N = 2e5 + 10;
const int M = 11111;
int dx[]={-1, 0, 1, 0};
int dy[]={0, 1, 0, -1};
using namespace std;

int num[M][M];

inline bool judge(int a,int b,int c,int d,int r){
    int len=(a-c)*(a-c)+(b-d)*(b-d);
    if(len<=r*r) return 1;
    else return 0;
}

inline void solve(){
    int n;
    cin>>n;
    int u,v;
    for(int i=1;i<=n;i++){
        cin>>u>>v;
        num[u][v]++;
    }
    int m;
    cin>>m;
    int res=0;
    int x,y,r;
    while(m--){
        cin>>x>>y>>r;
        for(int i=max(0,x-r);i<=min(x+r,10000);i++){
            for(int j=max(0,y-r);j<=min(y+r,10000);j++){
                if(judge(i,j,x,y,r)){
                    res+=num[i][j];
                    num[i][j]=0;
                }
            }
        }
    }
    cout<<n-res<<endl;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}

F - Floppy Music (补)

题目链接

答案

#include <iostream>
#include <algorithm>
#include<bits/stdc++.h>
#define ll long long
#define mem(a,b) memset(a,b,sizeof a)
#define ull unsigned long long
#define INF 0x3f3f3f3f3f3f3f3f
#define inf 0x3f3f3f3f
#define rep(i,a,b) for(auto i=a;i<=b;++i)
#define bep(i,a,b) for(auto i=a;i>=b;--i)
#define lowbit(x) x&(-x)
#define PII pair<int,int>
#define x first
#define y second
#define PLL pair<ll,ll>
#define PI acos(-1)
#define pb push_back
#define eb emplace_back
const double eps = 1e-6;
const int mod = 998244353;
const int MOD = 1e9 + 7;
const int N = 2e5 + 10;
const int M = 111;
int dx[]={-1, 0, 1, 0};
int dy[]={0, 1, 0, -1};
using namespace std;

int dp[N];
bool vp1[N];
bool vp2[N];

inline void solve(){
    int f;
    cin>>f;
    bool flag=0;
    while(f--){
        bool book=0;
        int t,n;
        cin>>t>>n;
        int a,b;
        for(int i=1;i<=n;i++){
            cin>>a>>b;
            dp[i]=b-a;
        }
        for(int i=0;i<=t;i++) vp1[i]=1;
        for(int i=1;i<=n;i++){
            mem(vp2,0);
            for(int j=0;j<=t;j++){
                if(vp1[j]){
                    if(j-dp[i]>=0) vp2[j-dp[i]]=1;
                    if(j+dp[i]<=t) vp2[j+dp[i]]=1;
                }
            }
            for(int j=0;j<=t;j++) vp1[j]=vp2[j];
        }
        for(int i=0;i<=t;i++){
            if(vp1[i]) book=1;
        }
        if(!book) flag=1;
    }
    if(!flag) puts("possible");
    else puts("impossible");
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值