第六届福建省程序设计竞赛题解

版权声明:学习,哪有那么多条条框框~ https://blog.csdn.net/Irish_Moonshine/article/details/80320713

A.Super Mobile Charger
小模拟,用充电宝给手机充电。

#include <iostream>
#include <stdio.h>
#include <algorithm>
using namespace std;
int a[123];

int main()
{
    int T;
    scanf("%d",&T);
    while(T--){
        int n,m;
        scanf("%d%d",&n,&m);
        for(int i=1;i<=n;i++) scanf("%d",&a[i]),a[i]=100-a[i];
        sort(a+1,a+1+n);
        int num=0;
        for(int i=1;i<=n;i++){
            if(m>=a[i]){
                num++;
                m-=a[i];
            }
        }
        printf("%d\n",num);
    }
}

B.Common Tangents
给你两个圆,判断公切线数量。

#include <iostream>
#include <stdio.h>
#include <cmath>
#include <algorithm>
using namespace std;
int a[123];

int main()
{
    int T;
    scanf("%d",&T);
    while(T--){
        int x1,y1,r1;
        int x2,y2,r2;
        scanf("%d%d%d%d%d%d",&x1,&y1,&r1,&x2,&y2,&r2);
        if(r1==r2&&x1==x2&&y1==y2){
            printf("-1\n");
            continue;
        }
        double dis = sqrt((1.0*x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));


        if(r1<r2){
            swap(r1,r2);
        }
        if(dis+r2<r1){
            printf("0\n");
        }else if (fabs(r1-r2-dis)<1e-8){
            printf("1\n");
        }else if(r1-r2<dis&&dis<r1+r2){
            printf("2\n");
        }else if(fabs(r1+r2-dis)<1e-8){
            printf("3\n");
        }else{
            printf("4\n");
        }
    }
}

C.Knapsack problem
超大0-1背包。要么模拟背包,要么将价值和背包反看。

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;

#define LL long long int


const int maxn = 500+55;
const LL inf = 0x3f3f3f3f;
LL w[maxn];
LL v[maxn];

LL val[5555];

int main()
{
    LL T;
    cin>>T;
    while(T--){
        LL n,m;
        cin>>n>>m;
        for(int i=1;i<=n;i++){
            cin>>w[i]>>v[i];
        }
        val[0]=0;
        for(int i=1;i<=5000;i++){
            val[i]=inf; 
        }
        for(int j=1;j<=n;j++){
            for(int i=5000;i>=0;i--){
                if(i-v[j]>=0)
                    val[i]=min(val[i],val[i-v[j]]+w[j]);
            }
        }
        for(int i=5000;i>=0;i--){
            if(val[i]<=m){
                cout<<i<<endl;
                break;
            }
        }
    }
    return 0;
}

D.Simple Polynomial Problem
E.The Longest Straight
最长连续+1上升子序列,顺子!

#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
using namespace std;
const int maxn = 100000+23;

int hav[maxn];
int num[maxn];
int main()
{
    int T;
    scanf("%d",&T);
    while(T--){
        int n,m;
        scanf("%d%d",&n,&m);
        int zero=0;
        memset(hav,0,sizeof hav);
        for(int i=1;i<=n;i++){
            int x;
            scanf("%d",&x);
            if(!x) zero++;
            else hav[x]=1;
        }
        for(int i=1;i<=m;i++){
            num[i]=num[i-1]+!hav[i];
        }
        int ans = 0;
        for(int i=1;i<=m;i++){
            int a=upper_bound(num+i, num+m+1,zero+num[i-1])-num;
            ans=max(ans,a-i);
        }
        printf("%d\n",ans);

    }



}

F.Taxi
G.Simple String Problem

H.StarCraft
哈夫曼构造法,用优先队列实现。

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<string>
#include<map>
#include<queue>
#include<vector>
#include<functional>
using namespace std;
#define ll long long int
#define INF 0x3f3f3f3f
priority_queue < int, vector<int>, greater<int> >q;

int main()
{
    int T;
    scanf("%d", &T);
    while (T--) {
        int x, n, m, k;
        scanf("%d%d%d", &n, &m, &k);
        for (int i = 0; i < n; i++) {
            scanf("%d", &x);
            q.push(x);
        }
        while (n > m) {
            q.pop();
            q.push(q.top() + k);
            q.pop();
            n--;
        }
        while (q.size() != 1)
            q.pop();
        printf("%d\n", q.top());
        q.pop();

    }
    return 0;
}
//_CRT_SECURE_NO_WARNINGS

I.Defender of Argus
J.RunningMan
小博弈,类似田忌赛马。

include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;

#define LL long long int


const int maxn = 500+55;

const LL inf = 123213213123LL;


int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        int m,n;int a;int b;
        scanf("%d%d",&m,&n);
        if(m%3==0)
        {
            a=b=m/3;
        }
        else if(m%3==2){
            a=m/3;
            b=a+1;
        }
        else
        {
            a=b=m/3;
        }
        if(n>=(a+b+2))
        {
            printf("No\n");
        }
        else{
            printf("Yes\n");
        }

    }
    return 0;
}
阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页