zoukankan      html  css  js  c++  java
  • T89359 扫雷

    T89359 扫雷

    题解

    朴素做法:暴力出奇迹

                      一维数组按道理不能开到1e7这么大吧,但是我开了井然 A 了 或许是rp问题

    #include<iostream>
    #include<cstdio>
    #include<string>
    #include<cstring>
    #include<algorithm>
    #include<cmath>
    #include<cstdlib>
    #include<queue>
    
    using namespace std;
    
    #define ll long long
    
    inline int read()
    {
        int ans=0;
        char last=' ',ch=getchar();
        while(ch<'0'||ch>'9') last=ch,ch=getchar();
        while(ch>='0'&&ch<='9') ans=ans*10+ch-'0',ch=getchar();
        if(last=='-') ans=-ans;
        return ans;
    }
    
    int n,k;
    long long ans=0;
    int a[10000010];
    
    bool cmp(int x,int y)
    {
        return x>y;
    }
    
    int main()
    {
        n=read();
        if(n%2==0)
        {
            printf("-1");
            return 0;
        }
        for(int i=1;i<=n;i++)
        {
            a[i]=read();
        }
        sort(a+1,a+n+1,cmp);
        for(int i=1;i<=n;i+=2)
        {
            if(a[i]!=a[i+1]){
                cout<<a[i];
                return 0;
            }
        }
        return 0;
    }

    脑洞做法:^

                      ^   满足交换律,把所有数字 ^ 起来,重复的数字就消失了,最后剩下的数字就是只出                          现一次的数字

    #include<iostream>
    #include<cstdio>
    #include<string>
    #include<cstring>
    #include<algorithm>
    #include<cmath>
    #include<cstdlib>
    #include<queue>
    
    using namespace std;
    
    #define ll long long
    
    inline int read()
    {
        int ans=0;
        char last=' ',ch=getchar();
        while(ch<'0'||ch>'9') last=ch,ch=getchar();
        while(ch>='0'&&ch<='9') ans=ans*10+ch-'0',ch=getchar();
        if(last=='-') ans=-ans;
        return ans;
    }
    
    int n,k,ans=0;
    
    int main()
    {
        n=read();
        for(int i=1;i<=n;i++)
        {
            k=read();
            if(i==1) ans=k;
            else ans=ans^k;
        }
        printf("%d",ans);
        return 0;
    }
  • 相关阅读:
    一个类GraphQL的ORM数据访问框架发布
    关于 IIS Express 常用设置
    代码失控与状态机(上)
    实体类的动态生成(三)
    实体类的动态生成(二)
    搭建 github.io 博客站点
    实体类的动态生成(一)
    JDK的下载和安装
    三步搞定jupyter nootebook 主题切换
    LeetCode刷题--存在重复元素
  • 原文地址:https://www.cnblogs.com/xiaoyezi-wink/p/11237098.html
Copyright © 2011-2022 走看看