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;
    }
  • 相关阅读:
    数据结构笔记
    简单数学
    分析代码练习--长期目标
    C#基础--面向对象计算器
    经常喜欢看的网站
    C#基础--面向过程计算器
    C#中的五个访问修饰符
    SQLServer 游标详解
    快速产生大量顺序数字序列
    VSCode 必装的 10 个高效开发插件
  • 原文地址:https://www.cnblogs.com/xiaoyezi-wink/p/11237098.html
Copyright © 2011-2022 走看看