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 263−1 .
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 263−1 .
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.
1≤T≤1000
1≤N≤62
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.
For each test,in the first line there is a number N ,and in the next line there are N numbers.
1≤T≤1000
1≤N≤62
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
题意就是选取一些数使得乘积最大。。。如果只有一个负数,显然要选,如果只有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 .
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 .
T≤1000 , 1≤N≤1000000 , 1≤M≤263 .
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.
In the next T lines there are two numbers N and M .
T≤1000 , 1≤N≤1000000 , 1≤M≤263 .
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
题意就是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 setTime 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≤ L≤5 , 1≤ Ai ≤10 , 1≤L≤N 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
Sample Output
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;
}