站外题求助(codeforcesICPC省赛题)
  • 板块学术版
  • 楼主CKAO
  • 当前回复0
  • 已保存回复0
  • 发布时间2023/6/9 20:11
  • 上次更新2023/10/23 13:34:07
查看原帖
站外题求助(codeforcesICPC省赛题)
583126
CKAO楼主2023/6/9 20:11

各位大佬们,2023江西省赛的C题 这题为什么转换p进制后在判断数位和的奇偶是错误的?求指正,孩子已经一天了没找出来,和标答对照各种样例都是对的!!!求大佬们有空帮我找一下错误!!万分感谢!!!!!!

#include<iostream>
#include<algorithm>
using namespace std;
const int N = 3e5 + 5;
long long p, a[N], n;
 
int f(long long x)
{
    int res = 0;
    while(x)
    {
        res += x%p %2;
        x /= p;
    }
    return res;
}
 
int main()
{
    cin>>n>>p;
    
    for (int i = 1; i <= n; i++)
        cin>>a[i];
    
    if (p == 1)
    {
        int ans =0;
        for (int i = 1; i <= n; i ++)
               ans += a[i] % 2;
        if (ans% 2) cout<<"GOOD";
        else cout<<"BAD";
    }
    else
    {
        int res = 0;
        for (int i = 1; i <= n; i++)
            res += f(a[i]);
        if (res % 2) cout<<"GOOD";
        else cout<<"BAD";
        
    }
    return 0;
}
2023/6/9 20:11
加载中...