22 条题解

  • 1
    @ 2017-08-18 01:37:22

    测试十万个数,极为保险!!!!!
    但真正AC代码链接——————大神代码

    #include <iostream>
    #include <cstdio>
    #include <cstdlib>
    #include <cmath>
    #include <cstring>
    #include <algorithm>
    using namespace std;
    int main()
    {
        int i,n,a[100001],b,m=0;
        scanf("%d",&n);
        for(i=1;i<=n;i++)
        {
            if(i<=100000)
                scanf("%d",&a[i]),m++;
            else
                getchar();
        }
        sort(a+1,a+1+m);
        printf("%d",a[m/2]);
        return 0;
    }
    
  • 0
    @ 2016-12-07 13:11:54

    STL

  • 0
    @ 2016-12-07 13:09:21

    STL必胜!!!!!!!!

  • 0
    @ 2016-09-09 15:30:17

    STL大法好

        评测结果
        编译成功
    
        测试数据 #0: Accepted, time = 0 ms, mem = 556 KiB, score = 10
        测试数据 #1: Accepted, time = 0 ms, mem = 556 KiB, score = 10
        测试数据 #2: Accepted, time = 0 ms, mem = 556 KiB, score = 10
        测试数据 #3: Accepted, time = 0 ms, mem = 552 KiB, score = 10
        测试数据 #4: Accepted, time = 0 ms, mem = 552 KiB, score = 10
        测试数据 #5: Accepted, time = 0 ms, mem = 556 KiB, score = 10
        测试数据 #6: Accepted, time = 0 ms, mem = 556 KiB, score = 10
        测试数据 #7: Accepted, time = 0 ms, mem = 560 KiB, score = 10
        测试数据 #8: Accepted, time = 0 ms, mem = 556 KiB, score = 10
        测试数据 #9: Accepted, time = 0 ms, mem = 556 KiB, score = 10
        Accepted, time = 0 ms, mem = 560 KiB, score = 100
        代码
        #include <cstdio>
        #include <map>
        using namespace std;
        map <int,int> vis;
        int main() {
            int n;
            scanf("%d",&n);
            while (n--) {
                int x;
                scanf("%d",&x);
                vis[x]++;
                if (vis[x] > 1) {
                    printf("%d",x);
                    break;
                }
            }
            return 0;
        }
    
  • 0
    @ 2015-11-07 14:40:56

    krew的方法,快膜

    var n,s,ans,i,x:longint;
    begin
    read(n);
    s:=0;
    ans:=23333;
    for i:=1 to n do
    begin
    read(x);
    if ans=x then inc(s)
    else
    if s=0 then begin s:=1;ans:=x;end
    else dec(s);
    end;
    write(ans);
    end.

    这种做法的前提是菊花数>n/2
    但是十分耗时

    科莫多龙

    PS:本题与codevs上 FFF 团卧底的菊花 完全一样

  • 0
    @ 2015-01-18 00:27:58

    晕,看来这题数据结构要求挺严格啊,明天用堆试试,

    嘛,靠运气算是勉强AC了- -(其实是懒得花时间想,pia~)等我明天有空好好想想再完美AC一次- -话说这种题目数据那么弱,试几下运气刚好就能过了

  • 0
    @ 2015-01-17 13:14:30

    这题怎么RP都没得加,看在我比较蠢(呸),看在题目比较可爱的份上我就来试试水吧- -

  • -1
    @ 2016-09-18 09:45:43

    随机取中间的100个数 输出出现次数最多的那个。。竟然神奇的AC了
    ```Pascal

    var
    a,b:array[1..100]of longint;
    i,j,n,id,ans,mid,x,max:longint;

    begin
    randomize;
    readln(n);
    mid:=random(n-100);
    if mid>0 then
    begin
    for i:=1 to mid do read(x);
    max:=100;
    end
    else max:=n;
    for i:=1 to max do read(a[i]);
    for i:=1 to max do
    for j:=1 to max do
    if a[j]=a[i] then inc(b[i]);
    for i:=1 to max do
    if b[i]>ans then
    begin
    id:=i;
    ans:=b[i];
    end;
    writeln(a[id]);
    end.
    ```
    随机化交了三遍 都AC
    我的记录
    我的所有递交记录
    09-18 Accepted
    09-18 Accepted
    09-18 Accepted
    10-19 Memory Exceeded
    10-19 Memory Exceeded

  • -1
    @ 2016-08-14 12:46:58

    这个方法很简单。
    就是开个a[99]的数组,a[0]代表个位数为0,a[1]代表个位数为1,a[10]代表十位数为0,以此类推。
    然后就读入n个数,每个数拆成10位,对每一位直接加就可以啦。

    #include<stdio.h>
    using namespace std;

    int a[100]={},n,x,i,j;
    bool ok;

    int main(){
    scanf("%d",&n);
    ok=false;
    for(i=1;i<=n;i++){
    scanf("%d",&x);
    j=0;
    while(j==0||x!=0){
    a[x%10+j*10]++;
    x/=10;j++;
    }
    }
    for(i=99;i>=0;i--){
    if(a[i]>=(n+1)/2&&(ok||i%10!=0||i==0)){
    ok=true;printf("%d",i%10);
    }
    }
    return 0;
    }

  • -1
    @ 2016-08-14 12:17:07

    /*
    此题巧妙利用了要求数一定出现超过一半,节约空间一个个数读入,用k来记录个数,
    运用+ -对消的方法求出出现最多的数
    注意一定要用scanf读入不然完美超时
    */
    #include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <cstring>
    using namespace std;

    int x,n;
    int k;

    int main()
    {
    scanf("%d%d",&n,&x);
    int a;
    for(int i=2;i<=n;i++)
    {
    scanf("%d",&a);
    if(a==x)
    k++;
    else if(k==0)
    x=a,k++;
    else k--;
    }
    cout<<x<<endl;
    return 0;
    }

  • -1
    @ 2015-08-03 10:53:39

    #include<cstdio>
    #include<cstring>
    using namespace std;
    int main()
    {
    int n,i,s=0,x,a;
    scanf("%d",&n);
    scanf("%d",&x);
    for(i=1;i<n;i++)
    {
    scanf("%d",&a);
    if(x==a)s++;
    else
    {
    if(s==0){x=a;s++;}
    else s--;
    }
    }
    printf("%d\n",x);
    return 0;
    }

  • -1
    @ 2015-04-06 18:56:34

    测试数据 #0: Accepted, time = 0 ms, mem = 712 KiB, score = 10
    测试数据 #1: Accepted, time = 0 ms, mem = 712 KiB, score = 10
    测试数据 #2: Accepted, time = 0 ms, mem = 712 KiB, score = 10
    测试数据 #3: Accepted, time = 0 ms, mem = 716 KiB, score = 10
    测试数据 #4: Accepted, time = 265 ms, mem = 716 KiB, score = 10
    测试数据 #5: Accepted, time = 265 ms, mem = 712 KiB, score = 10
    测试数据 #6: Accepted, time = 281 ms, mem = 712 KiB, score = 10
    测试数据 #7: Accepted, time = 234 ms, mem = 712 KiB, score = 10
    测试数据 #8: Accepted, time = 265 ms, mem = 712 KiB, score = 10
    测试数据 #9: Accepted, time = 281 ms, mem = 716 KiB, score = 10
    对每个数据段进行取样,每次选取最大的几个, 最后把选到最多的数输出,话说为什么我用了6*20000的数组要用这么多空间??……

  • -1
    @ 2015-01-20 22:04:01

    排序还是能过....

    测试数据 #0: Accepted, time = 0 ms, mem = 640 KiB, score = 10

    测试数据 #1: Accepted, time = 0 ms, mem = 640 KiB, score = 10

    测试数据 #2: Accepted, time = 0 ms, mem = 644 KiB, score = 10

    测试数据 #3: Accepted, time = 0 ms, mem = 644 KiB, score = 10

    测试数据 #4: Accepted, time = 15 ms, mem = 644 KiB, score = 10

    测试数据 #5: Accepted, time = 31 ms, mem = 644 KiB, score = 10

    测试数据 #6: Accepted, time = 31 ms, mem = 644 KiB, score = 10

    测试数据 #7: Accepted, time = 31 ms, mem = 644 KiB, score = 10

    测试数据 #8: Accepted, time = 15 ms, mem = 640 KiB, score = 10

    测试数据 #9: Accepted, time = 46 ms, mem = 640 KiB, score = 10

    Accepted, time = 169 ms, mem = 644 KiB, score = 100

  • -1
    @ 2015-01-19 23:08:01

    和判断一些数中是否有一个出现大于一半一样

    int main()
    {
    int pre, next, n, cnt = 0;
    scanf("%d", &n);
    scanf("%d", &pre);
    for (int i = 0; i < n - 1; i++)
    {
    scanf("%d", &next);
    if (pre == next) cnt++;
    else
    {
    if (cnt == 0) pre = next, cnt++;
    else cnt--;
    }
    }
    printf("%d\n", pre);
    return 0;
    }

  • -1
    @ 2015-01-19 19:48:08

    膜拜楼下大神。蒟蒻的我开了一个十万数组也过了,但很明显楼下的智商甩我n条街啊!!!唉

  • -1
    @ 2015-01-19 13:56:59

    #include<cstdio>
    #include<cstring>
    #include<cstdlib>
    #include<iostream>
    using namespace std;
    int main(){
    int n,a=0,cnt=0;
    scanf("%d",&n);
    for(int i=1; i<=n; i++){
    int b;
    scanf("%d",&b);
    if(cnt==0) {
    a=b;
    cnt++;
    }
    else if(a==b) cnt++;
    else cnt--;
    }printf("%d\n",a);
    return 0;
    }

  • -2
    @ 2016-12-07 13:14:11

    胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜
    胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜必必必必胜胜胜胜胜
    胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜必必必必必必必必必胜胜胜胜
    胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜必必必必必必必必必必必必必必必胜胜胜胜
    胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜必必必必必必必必必必必必必必必胜胜胜胜胜胜
    胜胜胜胜胜胜胜胜胜胜胜必必必必胜必必必必必必必必必必必胜胜胜胜胜胜胜胜胜胜
    胜胜胜胜胜胜胜胜必必必必必必必胜必必必胜胜必必必必必胜胜胜胜胜胜胜胜胜胜胜
    胜胜胜必必必必必必必必必必必必胜胜胜胜胜胜必必必必胜胜胜胜胜胜胜胜胜胜胜胜
    胜必必必必必必必必必必必必必必胜胜胜胜胜胜必必必必胜胜胜胜胜胜胜胜胜胜胜胜
    胜必必必必必必必必必必必必胜胜胜胜胜胜胜必必必必必必必必必必必胜胜胜胜胜胜
    胜必必必必必必必必必必必必胜胜胜胜胜胜必必必必必必必必必必必必必必胜胜胜胜
    胜胜必必必必必必必必必必胜胜胜胜胜必必必必必必胜胜胜必必必必必必必胜胜胜胜
    胜胜胜胜胜胜胜胜必必必必胜胜胜胜胜必必必必胜胜胜胜胜胜必必必必必胜胜胜胜胜
    胜胜胜胜胜胜胜胜必必必必胜胜胜胜必必必必胜胜必必胜胜胜必必必必必胜胜胜胜胜
    胜胜胜胜胜胜胜胜必必必必胜胜胜胜必必必必胜胜必必必必胜必必必必必胜胜胜胜胜
    胜胜胜胜胜胜胜胜必必必必胜胜胜胜必必必必胜胜必必必必胜必必必必必胜胜胜胜胜
    胜胜胜胜胜胜胜胜必必必必胜胜胜胜必必必必胜胜必必必胜胜必必必必必胜胜胜胜胜
    胜胜胜胜胜胜胜胜必必必必胜胜胜胜必必必必胜胜必必必胜胜必必必必必胜胜胜胜胜
    胜胜胜胜胜胜胜胜必必必必胜胜胜胜必必必必胜必必必必胜胜必必必必必胜胜胜胜胜
    胜胜胜胜胜胜胜胜必必必必胜胜胜胜必必必必胜必必必必胜胜必必必必必胜胜胜胜胜
    胜胜胜胜胜胜胜胜必必必必胜胜胜胜必必必必胜必必必必胜胜必必必必必胜胜胜胜胜
    胜胜胜胜胜胜胜胜必必必必胜胜胜胜必必必必胜必必必必胜胜必必必必必胜胜胜胜胜
    胜胜胜胜胜胜胜胜必必必必胜胜胜胜必必必胜胜必必必必胜胜必必必必必胜胜胜胜胜
    胜胜必必胜胜胜必必必必必胜胜胜胜必必必胜胜必必必胜胜胜必必必必必胜胜胜胜胜
    胜胜必必必必必必必必必必胜胜胜胜胜必必胜胜必必胜胜胜胜必必必必必胜胜胜胜胜
    胜胜胜必必必必必必必必必胜胜胜胜胜胜胜胜必必必胜胜胜胜必必必必胜胜胜胜胜胜
    胜胜胜胜胜必必必必必必必胜胜胜胜胜胜胜胜必必必胜必必必必胜胜胜胜胜胜胜胜胜
    胜胜胜胜胜胜必必必必必必胜胜胜胜胜胜胜必必必必胜胜必必必必胜胜胜胜胜胜胜胜
    胜胜胜胜胜胜胜胜胜必必必胜胜胜胜胜胜必必必必必胜胜胜必必必必必必必胜胜胜胜
    胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜必必必必必必胜胜胜胜胜必必必必必必胜胜胜胜
    胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜必必必必必必胜胜胜胜胜胜必必必必必必必胜胜胜
    胜胜胜胜胜胜胜胜胜胜胜胜胜胜必必必必必胜胜胜胜胜胜胜胜胜必必必必必必胜胜胜
    胜胜胜胜胜胜胜胜胜胜胜胜胜必必必必必胜胜胜胜胜胜胜胜胜胜胜必必必必胜胜胜胜
    胜胜胜胜胜胜胜胜胜胜胜胜必必必胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜必必必胜胜胜胜
    胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜

  • -2
    @ 2016-12-07 13:13:58

    胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜
    胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜必必必必胜胜胜胜胜
    胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜必必必必必必必必必胜胜胜胜
    胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜必必必必必必必必必必必必必必必胜胜胜胜
    胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜必必必必必必必必必必必必必必必胜胜胜胜胜胜
    胜胜胜胜胜胜胜胜胜胜胜必必必必胜必必必必必必必必必必必胜胜胜胜胜胜胜胜胜胜
    胜胜胜胜胜胜胜胜必必必必必必必胜必必必胜胜必必必必必胜胜胜胜胜胜胜胜胜胜胜
    胜胜胜必必必必必必必必必必必必胜胜胜胜胜胜必必必必胜胜胜胜胜胜胜胜胜胜胜胜
    胜必必必必必必必必必必必必必必胜胜胜胜胜胜必必必必胜胜胜胜胜胜胜胜胜胜胜胜
    胜必必必必必必必必必必必必胜胜胜胜胜胜胜必必必必必必必必必必必胜胜胜胜胜胜
    胜必必必必必必必必必必必必胜胜胜胜胜胜必必必必必必必必必必必必必必胜胜胜胜
    胜胜必必必必必必必必必必胜胜胜胜胜必必必必必必胜胜胜必必必必必必必胜胜胜胜
    胜胜胜胜胜胜胜胜必必必必胜胜胜胜胜必必必必胜胜胜胜胜胜必必必必必胜胜胜胜胜
    胜胜胜胜胜胜胜胜必必必必胜胜胜胜必必必必胜胜必必胜胜胜必必必必必胜胜胜胜胜
    胜胜胜胜胜胜胜胜必必必必胜胜胜胜必必必必胜胜必必必必胜必必必必必胜胜胜胜胜
    胜胜胜胜胜胜胜胜必必必必胜胜胜胜必必必必胜胜必必必必胜必必必必必胜胜胜胜胜
    胜胜胜胜胜胜胜胜必必必必胜胜胜胜必必必必胜胜必必必胜胜必必必必必胜胜胜胜胜
    胜胜胜胜胜胜胜胜必必必必胜胜胜胜必必必必胜胜必必必胜胜必必必必必胜胜胜胜胜
    胜胜胜胜胜胜胜胜必必必必胜胜胜胜必必必必胜必必必必胜胜必必必必必胜胜胜胜胜
    胜胜胜胜胜胜胜胜必必必必胜胜胜胜必必必必胜必必必必胜胜必必必必必胜胜胜胜胜
    胜胜胜胜胜胜胜胜必必必必胜胜胜胜必必必必胜必必必必胜胜必必必必必胜胜胜胜胜
    胜胜胜胜胜胜胜胜必必必必胜胜胜胜必必必必胜必必必必胜胜必必必必必胜胜胜胜胜
    胜胜胜胜胜胜胜胜必必必必胜胜胜胜必必必胜胜必必必必胜胜必必必必必胜胜胜胜胜
    胜胜必必胜胜胜必必必必必胜胜胜胜必必必胜胜必必必胜胜胜必必必必必胜胜胜胜胜
    胜胜必必必必必必必必必必胜胜胜胜胜必必胜胜必必胜胜胜胜必必必必必胜胜胜胜胜
    胜胜胜必必必必必必必必必胜胜胜胜胜胜胜胜必必必胜胜胜胜必必必必胜胜胜胜胜胜
    胜胜胜胜胜必必必必必必必胜胜胜胜胜胜胜胜必必必胜必必必必胜胜胜胜胜胜胜胜胜
    胜胜胜胜胜胜必必必必必必胜胜胜胜胜胜胜必必必必胜胜必必必必胜胜胜胜胜胜胜胜
    胜胜胜胜胜胜胜胜胜必必必胜胜胜胜胜胜必必必必必胜胜胜必必必必必必必胜胜胜胜
    胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜必必必必必必胜胜胜胜胜必必必必必必胜胜胜胜
    胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜必必必必必必胜胜胜胜胜胜必必必必必必必胜胜胜
    胜胜胜胜胜胜胜胜胜胜胜胜胜胜必必必必必胜胜胜胜胜胜胜胜胜必必必必必必胜胜胜
    胜胜胜胜胜胜胜胜胜胜胜胜胜必必必必必胜胜胜胜胜胜胜胜胜胜胜必必必必胜胜胜胜
    胜胜胜胜胜胜胜胜胜胜胜胜必必必胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜必必必胜胜胜胜
    胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜胜

  • -2
    @ 2016-12-07 13:13:46

    送张贤一个 必胜

  • -2
    @ 2016-12-07 13:13:22

    祝张贤成功

信息

ID
1917
难度
6
分类
其他 | 二分查找 点击显示
标签
(无)
递交数
668
已通过
184
通过率
28%
被复制
3
上传者