求助今晚入门赛的H题,除1和4测试点外全WA
  • 板块题目总版
  • 楼主lngym
  • 当前回复0
  • 已保存回复0
  • 发布时间2023/8/11 22:11
  • 上次更新2023/11/3 04:22:20
查看原帖
求助今晚入门赛的H题,除1和4测试点外全WA
494815
lngym楼主2023/8/11 22:11

麻烦大佬帮我看看我这么写有什么问题,非常感谢!

#include<bits/stdc++.h>
#define debug puts("bug\n")
using namespace std;
int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch>'9'||ch<'0')
    {
        if(ch=='-') f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9')
    {
        x=(x<<3)+(x<<1)+(ch^48);
        ch=getchar();
    }
    return x*f;
}
void write(int a)
{
    if(a<0)
    {
        putchar('-');
        a=-a;
    }
    if(a>9) write(a/10);
    putchar(a%10+'0');
}
int a[1000005];
bool check147(int n)
{
    if(n==1) return false;
    for(int i=1;i<=n;i++)
    {
        if(a[i]%147==0) return true;
    }
    bool judge49=false,judge3=false;
    for(int i=1;i<=n;i++)
    {
        if(a[i]%49==0) judge49=true;
        if(a[i]%3==0) judge3=true;
        if(judge49&&judge3) return true;
    }
    bool judge7=false,judge21=false;
    for(int i=1;i<=n;i++)
    {
        if(a[i]%7==0) judge7=true;
        if(a[i]%21==0) judge21=true;
        if(judge7&&judge21) return true;
    }
    return false;
}
bool check154(int n)
{
    if(n==1) return false;
    for(int i=1;i<=n;i++)
    {
        if(a[i]%154==0) return true;
    }
    bool judge77=false,judge2=false;
    for(int i=1;i<=n;i++)
    {
        if(a[i]%77==0) judge77=true;
        if(a[i]%2==0) judge2=true;
        if(judge77&&judge2) return true;
    }
    bool judge7=false,judge22=false;
    for(int i=1;i<=n;i++)
    {
        if(a[i]%7==0) judge7=true;
        if(a[i]%22==0) judge22=true;
        if(judge7&&judge22) return true;
    }
    bool judge11=false,judge14=false;
    for(int i=1;i<=n;i++)
    {
        if(a[i]%11==0) judge11=true;
        if(a[i]%14==0) judge14=true;
        if(judge11&&judge14) return true;
    }
    return false;
}
bool checkanother(int n,string s)
{
    long long sum=(long long)0;
    for(int i=1;i<=n;i++)
    {
        sum+=(long long)a[i];
    }
    string sum_string= to_string(sum);
    if(sum_string.length()>s.length()) return true;
    else if(sum_string.length()==s.length()&&sum_string>=s) return true;
    return false;
}
int main()
{
    int T=read();
    while(T--)
    {
        int n=read();
        string s;
        cin>>s;
        for(int i=1;i<=n;i++)
        {
            a[i]=read();
        }
        if(check147(n)) printf("Yes\n");
        else if(check154(n)) printf("Yes\n");
        else if(checkanother(n,s)) printf("Yes\n");
        else printf("No\n");
    }
    return 0;
}

2023/8/11 22:11
加载中...