BestCoder Round #70

Jam's math problem
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 479 Accepted Submission(s): 247


Problem Description
Jam has a math problem. He just learned factorization.
He is trying to factorize ax2+bx+c into the form of pqx2+(qk+mp)x+km=(px+k)(qx+m).
He could only solve the problem in which p,q,m,k are positive numbers.
Please help him determine whether the expression could be factorized with p,q,m,k being postive.


Input
The first line is a number T, means there are T(1≤T≤100) cases

Each case has one line,the line has 3 numbers a,b,c(1≤a,b,c≤100000000)


Output
You should output the "YES" or "NO".


Sample Input

2
1 6 5
1 6 4



Sample Output

YES
NO

Hint

The first case turn $x^2+6*x+5$ into $(x+1)(x+5)$




Source

BestCoder Round #70


解题思路:本体是一道模拟题,模拟ax2+bx+c=pqx2+(qk+mp)x+Km,使用一一枚举的方法来求出p,q,m,k的值。直接模拟的复杂度会超时,所以模拟到ab就行。

#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <cassert>
#include <queue>
#include <stack>
#pragma comment(linker,"/STACK:102400000,102400000")

using namespace std;

#define rep(i,a,n) for (int i=a;i<n;i++)//从a到n-1的循环
#define per(i,a,n) for (int i=n-1;i>=a;i--)//从n-1到a的循环
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define sqr(a) ((a)*(a))
#define lson(step) step<<1
#define rson(step) step<<1|1
#define mem(a,b) memset(a,b,sizeof(a))
#define Min(a,b) ((a)<(b)?(a):(b))
#define Max(a,b) ((a)>(b)?(a):(b))

typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1000000007;
const int INF = 0x3f3f3f3f;
ll powmod(ll a,ll b) {ll res=1;a%=mod;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}//快速幂取模,表示a^bmod1000000007
// head

int t,a,b,c;

int main()
{
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d %d %d",&a,&b,&c);
        queue<PII> Q1,Q2;
        int k = sqrt(a);
        int s = sqrt(c);
        for(int i=1;i<=k;i++)
        {
            if(a%i==0){
                Q1.push(mp(i,a/i));
                Q1.push(mp(a/i,i));
            }
        }
        for(int i=1;i<=s;i++)
        {
            if(c%i==0)
            {
                Q2.push(mp(i,c/i));
                Q2.push(mp(c/i,i));
            }
        }
        int len1 = Q1.size();
        int len2 = Q2.size();
        int flag  = 0;
        //queue<PII>::iterator it1,it2;
        for(int i=0;i<len1;i++)
        {
            for(int j=0;j<len2;j++)
            {
                PII aa,bb;
                aa = Q1.front();
                bb = Q2.front();
                if(aa.first*bb.second+aa.second*bb.first == b)
                {
                    flag = 1;
                    break;
                }
                Q2.push(bb);
                Q2.pop();
            }
            if(flag)
                break;
            Q1.pop();
        }
        if(flag)
            printf("YES\n");
        else
            printf("NO\n");
    }
    return 0;
}

Jam's balance
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 535 Accepted Submission(s): 258


Problem Description
Jim has a balance and N weights. (1≤N≤20)
The balance can only tell whether things on different side are the same weight.
Weights can be put on left side or right side arbitrarily.
Please tell whether the balance can measure an object of weight M.


Input
The first line is a integer T(1≤T≤5), means T test cases.
For each test case :
The first line is N, means the number of weights.
The second line are N number, i'th number wi(1≤wi≤100) means the i'th weight's weight is wi.
The third line is a number M. M is the weight of the object being measured.


Output
You should output the "YES"or"NO".


Sample Input

1
2
1 4
3
2
4
5



Sample Output

NO
YES
YES

Hint

For the Case 1:Put the 4 weight alone
For the Case 2:Put the 4 weight and 1 weight on both side




Source
BestCoder Round #70


解题思路:这道题可以放左边,可以放右边,N=20N=20N=20显然每种状态都枚举是不太现实的,因为每组砝码都可以变成很多种重量,当然也不排除有人乱搞过了这一题,其实这道题是一道贪心的思想,我们看到www不大,所以可以用010101背包扫一次,当然这还是不够的,这只能放一边,考虑到可以放另一边,就是可以有减的关系,所以反着再背包一遍,注意要判断边界。

我的方法大致相同:

#include<stdio.h>  
    #include<math.h>  
    #include<string.h>  
    #include<stack>  
    #include<set>  
    #include<queue>  
    #include<vector>  
    #include<iostream>  
    #include<algorithm>  
    #define MAXN 1010000  
    #define LL long long  
    #define ll __int64  
    #define INF 0xfffffff  
    #define mem(x) memset(x,0,sizeof(x))  
    #define PI acos(-1)  
    using namespace std;  
    int gcd(int a,int b){return b?gcd(b,a%b):a;}  
    LL powmod(LL a,LL b,LL MOD){LL ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}  
    //head  
    int vis[MAXN];  
    int sum[MAXN];  
    int main()  
    {  
        int t,n,m,a,i,j;  
        scanf("%d",&t);  
        while(t--)  
        {  
            scanf("%d",&n);  
            ll cnt=0;  
            mem(vis);mem(sum);  
            int M=0;  
            for(i=0;i<n;i++)  
            {  
                scanf("%d",&a);  
                for(j=1;j<=M;j++)  
                {  
                    if(vis[j])  
                    {  
                        sum[a+j]=1;  
                        sum[abs(a-j)]=1;  
                    }  
                }  
                sum[a]=1;  
                M+=a;  
                for(j=1;j<=M;j++)  
                vis[j]=sum[j];  
            }  
            scanf("%d",&m);  
            while(m--)  
            {  
                scanf("%d",&a);  
                if(a>=1&&a<=2000&&vis[a])  
                printf("YES\n");  
                else  
                printf("NO\n");  
            }  
        }  
        return 0;  
    }  


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值