第六届福建省大学生程序设计竞赛-重现赛

While HIT ACM Group finished their contest in Shanghai and is heading back Harbin, their train was delayed due to the heavy snow. Their mobile phones are all running out of battery very quick. Luckily, zb has a super mobile charger that can charge all phones.

There are N people on the train, and the i-th phone has p[i] percentage of power, the super mobile charger can charge at most M percentage of power.

Now zb wants to know, at most how many phones can be charged to full power. (100 percent means full power.)


Input

The first line contains an integer T, meaning the number of the cases (1 <= T <= 50.).

For each test case, the first line contains two integers N, M(1 <= N <= 100,0 <= M <= 10000) , the second line contains N integers p[i](0 <= p[i] <= 100) meaning the percentage of power of the i-th phone.

Output

For each test case, output the answer of the question.

Sample Input
2
3 10
100 99 90
3 1000
0 0 0
Sample Output
2
3


题意:给一个充电宝,问能给多少个手机充满电


水题

代码如下:

#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>

using namespace std;
typedef long long ll;

const int NMAX=105;
int a[NMAX];
int main()
{
    int t;
    int n,m;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d%d",&n,&m);
        for(int i=0;i<n;i++)
            scanf("%d",&a[i]);
        sort(a,a+n);
        int ans=0;
        for(int i=n-1;m>0&&i>=0;i--)
        {
            if(a[i]>=100)
                ans++;
            else
            {
                m=m-(100-a[i]);
                if(m>=0)
                    ans++;
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}

Problem Description

Two different circles can have at most four common tangents.

The picture below is an illustration of two circles with four common tangents.

Now given the center and radius of two circles, your job is to find how many common tangents between them.

Input

The first line contains an integer T, meaning the number of the cases (1 <= T <= 50.).

For each test case, there is one line contains six integers x1 (−100 ≤ x1 ≤ 100), y1 (−100 ≤ y1 ≤ 100), r1 (0 < r1 ≤ 200), x2 (−100 ≤ x2 ≤ 100), y2 (−100 ≤ y2 ≤ 100), r2 (0 < r2 ≤ 200). Here (x1, y1) and (x2, y2) are the coordinates of the center of the first circle and second circle respectively, r1 is the radius of the first circle and r2 is the radius of the second circle.

Output

For each test case, output the corresponding answer in one line.

If there is infinite number of tangents between the two circles then output -1.

Sample Input

310 10 5 20 20 510 10 10 20 20 1010 10 5 20 10 5

Sample Output

423

Source

第六届福建省大学生程序设计竞赛-重现赛(感谢承办方华侨大学)
题意:给两个圆,问两个圆的公共切线有多少条,若有无数多条切线输出-1


思路:

 首先特判两个圆是否是同一个圆,若是输出-1

然后依次判断两圆相离、外切、内切、内含的情况

注意该oj慎用long long 


代码如下:

#include<stdio.h>
#include<string.h>
#include<cmath>

int max(int a,int b)
{
    if(a>b)
        return a;
    return b;
}
int min(int a,int b)
{
    if(a>b)
        return b;
    return a;
}
int main()
{
    int t;
    int x1,x2,r1,r2,y1,y2;
    while(~scanf("%d",&t))
    {
        while(t--)
        {
            scanf("%d%d%d%d%d%d",&x1,&y1,&r1,&x2,&y2,&r2);
            int dis=(x2-x1)*(x2-x1)+(y2-y1)*(y2-y1),rmax=max(r1,r2),rmin=min(r1,r2);
            int r=(r1+r2)*(r1+r2);
            if(x1==x2&&y1==y2&&r1==r2)
                printf("-1\n");
            else if(dis>r)
                printf("4\n");
            else if(dis==r)
                printf("3\n");
            else if(dis>(rmax-rmin)*(rmax-rmin))
                printf("2\n");
            else if(dis==(rmax-rmin)*(rmax-rmin))
                printf("1\n");
            else
                printf("0\n");
        }
    }
    return 0;
}


Given a set of n items, each with a weight w[i] and a value v[i], determine a way to choose the items into a knapsack so that the total weight is less than or equal to a given limit B and the total value is as large as possible. Find the maximum total value. (Note that each item can be only chosen once).


Input

The first line contains the integer T indicating to the number of test cases.

For each test case, the first line contains the integers n and B.

Following n lines provide the information of each item.

The i-th line contains the weight w[i] and the value v[i] of the i-th item respectively.

1 <= number of test cases <= 100

1 <= n <= 500

1 <= B, w[i] <= 1000000000

1 <= v[1]+v[2]+...+v[n] <= 5000

All the inputs are integers.

Output

For each test case, output the maximum value.

Sample Input
1
5 15
12 4
2 2
1 1
4 10
1 2
Sample Output
15

水题,01背包(数组的大小尽可能开大点,不要正好)

代码如下:

#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;

const int N=505;
const int M=5006;
const int INF=0x3f3f3f3f;
int w[N],v[N];
int dp[N][M];
int min(int b,int c)
{
    if(b<c)
        return b;
    else
        return c;
}
void init()
{
    for(int i=0;i<N;i++)
        for(int j=0;j<M;j++)
            dp[i][j]=INF;
}
int main()
{
    int t,n,b;
    while(~scanf("%d",&t))
    {
        while(t--)
        {
            scanf("%d%d",&n,&b);
            int sum=0,i,j;
            for(i=1;i<=n;i++)
            {
                scanf("%d%d",&w[i],&v[i]);
                sum+=v[i];
            }
            init();
            for(i=0;i<=n;i++)
                dp[i][0]=0;
            for(i=1;i<=n;i++)
            {
                for(j=1;j<=sum;j++)
                {
                    if(j-v[i]>=0)
                        dp[i][j]=min(dp[i-1][j-v[i]]+w[i],dp[i-1][j]);
                    else
                        dp[i][j]=dp[i-1][j];
                }
            }
            for(i=sum;i>=0;i--)
            {
                if(dp[n][i]<=b)
                    break;
            }
            printf("%d\n",i);
        }
    }
    return 0;
}



ZB is playing a card game where the goal is to make straights. Each card in the deck has a number between 1 and M(including 1 and M). A straight is a sequence of cards with consecutive values. Values do not wrap around, so 1 does not come after M. In addition to regular cards, the deck also contains jokers. Each joker can be used as any valid number (between 1 and M, including 1 and M).

You will be given N integers card[1] .. card[n] referring to the cards in your hand. Jokers are represented by zeros, and other cards are represented by their values. ZB wants to know the number of cards in the longest straight that can be formed using one or more cards from his hand.


Input

The first line contains an integer T, meaning the number of the cases.

For each test case:

The first line there are two integers N and M in the first line (1 <= N, M <= 100000), and the second line contains N integers card[i] (0 <= card[i] <= M).

Output

For each test case, output a single integer in a line -- the longest straight ZB can get.

Sample Input
2
7 11
0 6 5 3 0 10 11
8 1000
100 100 100 101 100 99 97 103
Sample Output
5
3

题意:

给n张卡片(0----m),0是特殊卡片可以转化成任意卡片,问递增连续卡片的最大个数,卡片排列顺序是任意的。


思路:

贪心,将卡片的数字映射下来。将数组中元素为零,就用0来补,发现不能补了,就把最前的0拿出来补在后面,更新最值,需要特判,若特殊卡片0太多,就输出m

代码如下:

#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>

using namespace std;
bool mapp[100003];
int loc[100003];
int main()
{
    int t;
    int n,m;
    int ans,x;
    scanf("%d",&t);
    while(t--)
    {
        ans=0;
        scanf("%d%d",&n,&m);
        memset(mapp,false,sizeof(mapp));
        for(int i=0;i<n;i++)
        {
            scanf("%d",&x);
            if(!x)
                ans++;
            mapp[x]=true;
        }
        loc[0]=0,mapp[m+1]=0;
        int len=1,maxx=0,l=0,k=0,flag=0;
        //printf("%d\n",ans);
        for(int i=1;i<=m+1;i++)
        {
            if(!mapp[i])
            {
                loc[len++]=i;
                l++;
                if(l>ans)
                {
                    maxx=max(maxx,i-loc[k++]-1);
                    //printf("%d %d\n",i,i-loc[k-1]-1);
                    l--;
                    flag=1;
                }
            }
        }
        if(flag)
            printf("%d\n",maxx);
        else
            printf("%d\n",m);
    }

    return 0;
}





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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值