深夜切题——Divisible&Equality

Divisible
时间限制:1000MS  内存限制:65535K

Description
Given n + m integers, I1,I2,...,In,T1,T2,...,Tm, we want to know whether (I1*I2*...*In)%(T1*T2*...*Tm)= =0.

输入格式
The first line gives two integers n and m. 1<=n,m<=100
The second line gives n integers I1 I2 ... In.
The third line gives m integers T1 T2 ... Tn.
1<=Ii, Ti<=231

输出格式
Satisfy (I1*I2*...*In)%(T1*T2*...*Tm)= =0, output "yes", otherwise output "no"

输入样例
2 3
24 14
2 7 3

输出样例
yes


#include <cstdio>
#include <cstring>
#include <cmath>
#include <queue>
#include <vector>
#include <string>
#include <stack>
#include <set>
#include <map>
#include <iostream>
#include <bitset>
#include <algorithm>
using namespace std;

#define rep(s,n,up) for(int i = (s); i < (n); i+=(up))
#define per(n,e,down) for(int i = (n); i >= (e); i-=(down))
#define rep1(s,n,up) for(int j = (s); j < (n); j+=(up))
#define per1(n,e,down) for(int j = (n); j >= (e); j-=(down))

typedef long long LL;

LL gcd(LL a,LL b){
    LL mod=a%b;
    while(mod){
        a=b;
        b=mod;
        mod=a%b;
    }
    return b;
}

int I[100005],T[100005];

int main() {
    int n,m;
    scanf("%d",&n);scanf("%d",&m);
    rep(0,n,1)scanf("%d",&I[i]);sort(I,I+n);
    rep(0,m,1)scanf("%d",&T[i]);sort(T,T+m);
    per(n-1,0,1){
        rep1(0,m,1){
            int mod=gcd(I[i],T[j]);
            if(T[j]!=1&&I[i]!=1&&mod!=1&&!(I[i]%mod))
            {
                I[i]/=mod;
                T[j]/=mod;
            }
        }
    }
    int flag=1;
    rep(0,m,1)if(T[i]>1){flag=0;break;}
    if(flag)printf("yes\n");
    else printf("no\n");
    return 0;
}


---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Equality
时间限制:1000MS  内存限制:65535K

Description
Do you know the problem “Divisible” in SCAUCPC 2013? No? It does not matter. Today, I will introduce a similar thing to you.
You are given N numbers to multiply into a single number A, and another M numbers into number B.
However, because WJMKQDM does not like large number, the absolute values of each sub-number of A or B, which means Ai or Bi, will not larger than three.
Your task is extremely simple, that is to decide whether A is equal to B.
To make the problem a little more technical, you should notice that N and M will be a little large.

输入格式
First line of input is the number of test cases, less than 30.
In each case, there will be 2 line. The first line of each case represents number A in such format:
N A1 A2 .. AN, where A = A1 * A2 * .. * AN.
The second line, similarly, number B will be represent like this:
M B1 B2 .. BM, where B = B1 * B2 * .. * BM.
(1 <= N, M <= 100000)

输出格式
For each test case, output one line “Yes” or “No”(without quotation), corresponding to equality or inequality.

输入样例
2
2 2 3
3 3 2 1
3 1 2 3
2 2 2


输出样例
Yes
No


提示
Huge input, and scanf strongly recommended.

来源 LyonLys 


重点来了。。。这道题我暴力解靠着RP过了。。。再提交一次早就超时


/*

渣渣代码请无视

*/

//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <cstring>
#include <cmath>
#include <queue>
#include <vector>
#include <string>
#include <stack>
#include <set>
#include <map>
#include <iostream>
#include <bitset>
#include <algorithm>
using namespace std;

#define MP make_pair
#define PB push_back
#define mst(a,b) memset((a),(b),sizeof(a))
#define TEST cout<<"*************************"<<endl

#define rep(s,n,up) for(int i = (s); i < (n); i+=(up))
#define per(n,e,down) for(int i = (n); i >= (e); i-=(down))
#define rep1(s,n,up) for(int j = (s); j < (n); j+=(up))
#define per1(n,e,down) for(int j = (n); j >= (e); j-=(down))

typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int, int> Pii;
typedef vector<int> Vi;
typedef vector<Pii> Vii;
const int inf = 0x3f3f3f3f;
const LL INF = (1uLL << 63) - 1;
const double Pi = acos(-1.0);
const int maxn = (1 << 16) + 7;
const uLL Hashmod = 29050993;
const double esp=1e-6;


//#define local



int I[100005],T[100005];



int main() {
#ifdef local
    freopen("input.txt", "r", stdin);
    //freopen("output.txt","w",stdout);
#endif
    //ios::sync_with_stdio(0);
    //cin.tie();
    int c,n,m;
    scanf("%d",&c);
    while(c--){
        int zeroi=0,zerot=0;
        int ixnegative=0,ixtwo=0,ixthree=0;
        int txnegative=0,txtwo=0,txthree=0;
        scanf("%d",&n);
        rep(0,n,1){scanf("%d",&I[i]);if(I[i]==0)zeroi=1;else if(!zeroi){if(I[i]<0)++ixnegative;switch(abs(I[i])){
            case 3:++ixthree;break;
            case 2:++ixtwo;break;
            }}}
        scanf("%d",&m);
        rep(0,m,1){scanf("%d",&T[i]);if(T[i]==0)zerot=1;else if(!zerot){if(T[i]<0)++txnegative;switch(abs(T[i])){
            case 3:++txthree;break;
            case 2:++txtwo;break;
            }}}
        if(!zeroi&&!zerot){
            if((ixnegative%2)==(txnegative%2)){
                if(ixtwo==txtwo&&ixthree==txthree)
                    printf("Yes\n");
                else printf("No\n");
            }
            else printf("No\n");
        }
        else if(zeroi==zerot)printf("Yes\n");
        else printf("No\n");
    }
    return 0;
}

那就这样吧。能力不行, 我太弱鸡了(|-|)


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值