首页 > 其他分享 >CF1593D2. Half of Same

CF1593D2. Half of Same

时间:2024-05-30 20:31:09浏览次数:27  
标签:tmp arr CF1593D2 int cnt Same pos ++ Half

题目链接:

Half of Same - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)

WA代码:

#include<bits/stdc++.h>
using namespace std;
#define MAX 44
const int N = 2e6+6;
int arr[MAX];
int cnt_1[N];//记录每个数出现的次数
int cnt_2[N];//记录每个因数
int main(){
    int t;cin >> t;
    while(t--){
        int n;cin >> n;
        int ans = 0,pos = 0;
        memset(cnt_1, 0, sizeof(cnt_1));
        memset(arr, 0, sizeof(arr));
        for(int i = 0; i < n; i++){  
            int tmp;cin>>tmp;
            if(cnt_1[tmp+1000000]==0)//不是一样的数
                arr[pos++] = tmp;
            if(++cnt_1[tmp+1000000]>=n/2)//判断是否个数>=n/2
                ans = -1;
        }
        if(pos>2){
            sort(arr,arr+pos);
            for(int i = 0; i < pos - 1; i++){
                int tmp_1;//记录差值
                memset(cnt_2,0,N);
                for(int j = i + 1; j < pos; j++){
                    tmp_1 = arr[j]-arr[i];
                    for(int k = 1; k <= sqrt(tmp_1); k++){
                        if(tmp_1%k==0){
                            cnt_2[k] += cnt_1[arr[j] + 1000000];
                            if(k*k!=tmp_1) 
                            cnt_2[tmp_1/k]+=cnt_1[arr[j]+1000000];
                        }
                    }
                }
                while(cnt_2[tmp_1]<(n/2-cnt_1[arr[i]+1000000])&&tmp_1) tmp_1--;
                ans = max(ans,tmp_1);
            }
        }
        cout<<ans<<endl;
    }
}

测试点信息


46ms/15.30MB
WA
#6
Wrong Answer.wrong answer 2nd numbers differ - expected: '-1', found: '15495'
我初步判断是不是我漏掉了哪种情况但是我看题解没有得出结论。

标签:tmp,arr,CF1593D2,int,cnt,Same,pos,++,Half
From: https://blog.csdn.net/2301_80557641/article/details/139333783

相关文章

  • error Conflict: Multiple assets emit different content to the same filename ind
    ERRORFailedtocompilewith1error20:32:04errorConflict:Multipleassetsemitdifferentcontenttothesamefilenameindex.htmlERRORinConflict:Multipleassetsemitdif......
  • Tensors of the same index must be on the same device and the same dtype except `
    避免使用 torch.set_default_dtype(torch.float64) 可以尝试采用model.Double或者model.to(torch.Double)m=torch().to(device).to(torch.float64)     参考:Tensorsofthesameindexmustbeonthesamedeviceandthesamedtypeexcept`step`t......
  • MindSpore强化学习:使用PPO配合环境HalfCheetah-v2进行训练
    本文分享自华为云社区《MindSpore强化学习:使用PPO配合环境HalfCheetah-v2进行训练》,作者:irrational。半猎豹(HalfCheetah)是一个基于MuJoCo的强化学习环境,由P.Wawrzyński在“ACat-LikeRobotReal-TimeLearningtoRun”中提出。这个环境中的半猎豹是一个由9个链接和8个关节......
  • SpringBoot的Cookie sameSite之坑
    https://blog.csdn.net/weixin_38296425/article/details/111941318 CSDN上很多文章给出了解决CookiesameSite坑跨域之坑的解决办法,但是都忽略了一个问题,没有给出相关的依赖,我也是费了不少劲终于找到了解决办法,在这里记录下来。例如下面的代码:@ConfigurationpublicclassT......
  • Redis报错:CROSSSLOT Keys in request don't hash to the same slot的解决方案
    最近,项目上线的时候,出现了一个Redis的报错:CROSSSLOTKeysinrequestdon'thashtothesameslot,这个在内网环境下无法复现,因为正式环境的Redis是cluster集群模式,而我们内网环境是单机模式。(后面我在内网也部署了一个Redis集群,具体见我这一篇文章《使用Docker搭建RedisCluste......
  • because it set 'X-Frame-Options' to 'sameorigin'
    报错becauseitset'X-Frame-Options'to'sameorigin'.Refusedtodisplay'https://xxx.xxx.cn/'inaframebecauseitset'X-Frame-Options'to'sameorigin'.解决方法:修改页面,增加meta配置<head><!--CSP......
  • both methods have same erasure, yet neither overrides the other
    泛型,作为JDK5时代引入的”语法糖“,在编译的时候是会被抹除的,换言之,specialSort(List<Dog>)和specialSort(List<Apple>)在编译时都会变成specialSort(List),因此不符合重载的原则(变量名相同、参数类型或数量不同)。参考:https://blog.csdn.net/m0_37676618/article/details/106714182......
  • [965] Generate a new empty DataFrame with the same columns as an existing DataFr
    TogenerateanewemptyDataFramewiththesamecolumnsasanexistingDataFrameinPandas,youcanusethepd.DataFrameconstructorandpassthecolumnsfromtheexistingDataFrame.Here'sanexample:importpandasaspd#SampleDataFrameexisti......
  • CodeForces 1266F Almost Same Distance
    洛谷传送门CF传送门好厉害。特判\(k=1\)。首先经过观察,我们可以按照\(k\)的奇偶性讨论:\(k\)为偶数,有一个中心点挂了若干条长度为\(\frac{k}{2}\)的链。\(k\)为偶数,有两个中心点,两边挂了若干条长度为\(\frac{k}{2}\)的链;\(k\)为奇数,有一个中心点挂了若干条长度......
  • gh-ost 报错 ERROR 1236 (HY000): A slave with the same server_uuid/server_id as t
    使用gh-ost 对表在线加索引时,第一次发生了下面的报错(使用gh-ost很长时间了,第一次遇到这个报错):[2023/12/1211:48:08][error]binlogstreamer.go:77closesyncwitherr:ERROR1236(HY000):Aslavewiththesameserver_uuid/server_idasthisslavehasconnectedtoth......