BestCoder Round #60 div2 A B C HDU 5504 5505 5506

本文精选了多个技术领域的核心内容,包括前端、后端、移动开发、游戏开发、大数据开发等,深入剖析各领域关键技术和应用实例,提供丰富的实践经验和理论知识,帮助开发者深入理解并掌握关键技术点。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

GT and sequence

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 821    Accepted Submission(s): 195


Problem Description
You are given a sequence of N integers.

You should choose some numbers(at least one),and make the product of them as big as possible.

It guaranteed that **the absolute value of** any product of the numbers you choose in the initial sequence will not bigger than 2631 .
 

Input
In the first line there is a number T (test numbers).

For each test,in the first line there is a number N ,and in the next line there are N numbers.

1T1000
1N62

You'd better print the enter in the last line when you hack others.

You'd better not print space in the last of each line when you hack others.
 

Output
For each test case,output the answer.
 

Sample Input
   
1 3 1 2 3
 

Sample Output
   
6
 

Source
 

Recommend
hujie   |   We have carefully selected several similar problems for you:   5508  5507  5503  5502  5498 
 


题意就是选取一些数使得乘积最大。。。如果只有一个负数,显然要选,如果只有0,显然要输出0,后面sort一下,分类就行了。


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <cmath>
#include <cstring>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
typedef long long ll;
int main()
{
    ll a[64];
    ll  c[64];
    int i;
    int n,t;
    scanf("%d",&t);
    while(t--)
    {
        ll sum2=1;
        int len1=0;
        int zheng=0;
        int fu=0;
        scanf("%d",&n);
        for(i=0; i<n; i++)
        {
            scanf("%lld",&a[i]);
            if(a[i]<0)
            {
                c[len1++]=a[i];
                fu++;
            }
            else if(a[i]>0)
            {
                sum2*=a[i];
                zheng++;
            }
        }
        if(zheng==0)
        {
            if(fu==0)
            {
                puts("0");
                continue;
            }
            if(fu==1)
            {
                if(n==1)
                {
                    cout<<c[0]<<endl;
                    continue;
                }
                else
                {
                    puts("0");
                    continue;
                }
            }
        }
        sort(c,c+len1);
        if(len1%2==0)
            for(i=0; i<len1; i++)
                sum2*=c[i];
        else
            for(i=0; i<len1-1; i++)
                sum2*=c[i];
        cout<<sum2<<endl;
    }
    return 0;
}




GT and numbers

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 546    Accepted Submission(s): 160


Problem Description
You are given two numbers N and M .

Every step you can get a new N in the way that multiply N by a factor of N .

Work out how many steps can N be equal to M at least.

If N can't be to M forever,print 1 .
 

Input
In the first line there is a number T . T is the test number.

In the next T lines there are two numbers N and M .

T1000 , 1N1000000 , 1M263 .

Be careful to the range of M.

You'd better print the enter in the last line when you hack others.

You'd better not print space in the last of each line when you hack others.
 

Output
For each test case,output an answer.
 

Sample Input
   
3 1 1 1 2 2 4
 

Sample Output
   
0 -1 1
 

Source
 

Recommend
hujie   |   We have carefully selected several similar problems for you:   5508  5507  5503  5502  5498 
 

题意就是n的因子*n,问能不能变成m,输出最少操作步数。。首先特判几个情况。然后每次求出m和n的gcd,n不断的乘上去就好了,。gcd为1则无解。
还有一个坑点就是m的范围超 long long 所以上unsigned

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <cmath>
#include <cstring>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
typedef long long ll;
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        unsigned long long n,m;
        scanf("%llu%llu",&n,&m);
        if((n==1 &&m!=1) || m%n!=0)
        {
            puts("-1");
            continue;
        }
        if(n==m)
        {
            puts("0");
            continue;
        }
        int res=0;
        int flag=0;
        while(n!=m)
        {
            unsigned long long  temp=m/n;
            unsigned long long gcd=__gcd(temp,n);
            if(gcd==1)
            {
                flag=1;
                break;
            }
            n=gcd*n;
            res++;
        }
        if(!flag)
            printf("%d\n",res);
        else
            puts("-1");
    }
    return 0;
}





GT and set

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 83    Accepted Submission(s): 24


Problem Description
You are given N sets.The i th set has Ai numbers.

You should divide the sets into L parts.

And each part should have at least one number in common.

If there is at least one solution,print YES ,otherwise print NO .
 

Input
In the first line there is the testcase T ( T 20 )

For each teatcase:

In the first line there are two numbers N and L .

In the next N lines,each line describe a set.

The first number is Ai ,and then there are Ai distict numbers stand for the elements int the set.

The numbers in the set are all positive numbers and they're all not bigger than 300 .

1 N 30 1 L5 1 Ai 10 1LN

You'd better print the enter in the last line when you hack others.

You'd better not print space in the last of each line when you hack others.
 

Output
For each test print YES or NO
 

Sample Input
       
2 2 1 1 1 1 2 3 2 3 1 2 3 3 4 5 6 3 2 5 6
 

Sample Output
       
NO YES
Hint
For the second test,there are three sets:{1,2,3},{4,5,6},{2,5,6} You are asked to divide into two parts. One possible solution is to put the second and the third sets into the same part,and put the first in the other part. The second part and the third part have same number 6. Another solution is to put the first and the third sets into the same part,and put the second in the other part.
 

Source
 

Recommend




题意就是能不能将n个集合合并成L个部分,并且每个部分有一个共同的数。。我们可以将每个共同的数看成一个集合。然后做L次循环找1~n是否被覆盖。。
因为n,L 都很小,暴力即可。

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <cmath>
#include <cstring>
#include <vector>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
typedef long long ll;
vector<int> vp[400];
bool vis[350];
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int i,j,k;
        for(i=0; i<400; i++)
            vp[i].clear();
        memset(vis,false,sizeof(vis));
        int n,l;
        scanf("%d%d",&n,&l);
        for(i=1; i<=n; i++)
        {
            int x;
            scanf("%d",&x);
            for(j=0; j<x; j++)
            {
                int tmp;
                scanf("%d",&tmp);
                vp[tmp].push_back(i);
            }
        }
        for(i=0; i<l; i++)
        {
            int max=-1;
            int value=-1;
            for(j=1; j<=300; j++)
            {
                int cnt=0;
                for(k=0; k<vp[j].size(); k++)
                {
                    if(!vis[vp[j][k]])
                    {
                        // printf("vp[%d][%d]=%d  \n",j,k,vp[j][k]);
                        cnt++;
                    }
                }
                if(cnt>max)
                {
                    max=cnt;
                    value=j;
                    //printf("max=%d    value=%d  \n",max,value);
                }
            }
            if(value>=0)
            {
                for(j=0; j<vp[value].size(); j++)
                {
                    vis[vp[value][j]]=1;
                }
            }
        }
        for(i=1; i<=n; i++)
            if(!vis[i])
                break;
        if(i==n+1)
            printf("YES\n");
        else
            printf("NO\n");
    }
    return 0;
}







评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值