Codeforces Round #500 (Div. 2) ABC

A. Piles With Stones

水题略

B. And

题意:让输入一个n,一个下,之后输入一个长为n的数组a,可以在a中使a变为a&x,问经过几次变化数组中有相同的数

思路:当数组中有两个相同的数时直接输出0,注意a&x后的数无论在与x经过几次按位与运算都不会发生变化,

该题有特殊情况,在数据相当大时可能出现错误,因此要ans=min(ans,1或2),在这最后系统wa了,难受emmmmm

知识点补充:只有1&1=1

代码:

#include <bits/stdc++.h>

using namespace std;

int n,x;
long long a[200000+10],vis[200000+10];

map<long long,long long>mp;
map<long long,long long>mp1;

int main()
{
    ios::sync_with_stdio(false);cin.tie(0);
    cin>>n>>x;
    mp.clear();
    for(int i=0;i<n;i++){
        cin>>a[i];
        mp[a[i]]++;
    }
    map<long long,long long>::iterator it=mp.begin();

    for(it;it!=mp.end();it++){
        if((it->second)>1){
            cout<<"0"<<endl;
            return 0;
        }
    }

    mp1.clear();int ans=3;
    for(int i=0;i<n;i++){
        int m=a[i]&x;

        if(mp[m]!=0&&m!=a[i])
        {
            ans=min(ans,1);
        }
        else if(mp1[m]!=0){
                ans=min(ans,2);
        }
        else mp1[m]++;
    }

    if(ans==3) cout<<"-1"<<endl;
    else cout<<ans<<endl;

    return 0;
}

原文地址:https://www.cnblogs.com/Fy1999/p/9393379.html

时间: 2024-10-08 22:23:31

Codeforces Round #500 (Div. 2) ABC的相关文章

Codeforces Round #247 (Div. 2) ABC

Codeforces Round #247 (Div. 2) http://codeforces.com/contest/431 代码均已投放:https://github.com/illuz/WayToACM/tree/master/CodeForces/431 A - Black Square 题目地址 题意: Jury玩别踩白块,游戏中有四个区域,Jury点每个区域要消耗ai的卡路里,给出踩白块的序列,问要消耗多少卡路里. 分析: 模拟水题.. 代码: /* * Author: illuz

Codeforces Round #500 (Div. 2) [based on EJOI]

Codeforces Round #500 (Div. 2) [based on EJOI] https://codeforces.com/contest/1013 A 1 #include<bits/stdc++.h> 2 using namespace std; 3 #define lson l,mid,rt<<1 4 #define rson mid+1,r,rt<<1|1 5 #define IT set<node>::iterator 6 #def

Codeforces Round #366 (Div. 2) ABC

Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 1 #I hate that I love that I hate it 2 n = int(raw_input()) 3 s = "" 4 a = ["I hate that ","I love that ", "I hate it","I love it"] 5 fo

Codeforces Round #443 (Div. 2)ABC

A. Borya's Diagnosis It seems that Borya is seriously sick. He is going visit n doctors to find out the exact diagnosis. Each of the doctors needs the information about all previous visits, so Borya has to visit them in the prescribed order (i.e. Bor

Codeforces Round #451 (Div. 2) ABC

A. Rounding Vasya has a non-negative integer n. He wants to round it to nearest integer, which ends up with 0. If n already ends up with 0, Vasya considers it already rounded. For example, if n = 4722 answer is 4720. If n = 5 Vasya can round it to 0 

Codeforces Round #500 (Div. 2) BC

CodeForces 1013B And CodeForces 1013C  Photo of The Sky B 可以发现只有一次与操作是有意义的,所以答案只有-1,0,1,2四种情况 1 #include <bits/stdc++.h> 2 #define show(a) cout << #a << " = " << a << endl; 3 const int MOD = 1e9+7; 4 const int MAXN

Codeforces Round #312 (Div. 2) ABC题解

[比赛链接]click here~~ A. Lala Land and Apple Trees: [题意]: AMR住在拉拉土地.拉拉土地是一个非常美丽的国家,位于坐标线.拉拉土地是与著名的苹果树越来越随处可见. 拉拉土地恰好n苹果树.树数i位于位置xi和具有人工智能的苹果就可以了增长.阿姆鲁希望从苹果树收集苹果. AMR目前维持在X =0的位置.在开始的时候,他可以选择是否去左边或右边.他会在他的方向继续下去,直到他遇见一棵苹果树,他之前没有参观.他会采取所有的苹果,然后扭转他的方向,继续走这

Codeforces Round #429 (Div. 2)ABC

A: 题意:n个东西,k个朋友,全部给朋友,每个朋友不可以拿同样的,问是否可行 1 #include<bits/stdc++.h> 2 using namespace std; 3 4 map<char ,int >ma; 5 int main(){ 6 int n,k; 7 cin>>n>>k; 8 string s; 9 cin>>s; 10 for(int i=0;i<n;i++){ 11 ma[s[i]]++; 12 if(ma[s

Codeforces Round #450 (Div. 2)ABC

A. Find Extra One You have n distinct points on a plane, none of them lie on OY axis. Check that there is a point after removal of which the remaining points are located on one side of the OY axis. Input The first line contains a single positive inte