回 帖 发 新 帖 刷新版面

主题:第58次编程比赛初测 & 最终结果

[color=0000FF]初测结果:[/color]

我直接复制原作者的代码测试的,结果发现这样的话没有一份代码能通过测试
绝大多数代码是WA,少数代码是CE,TLE和RE
现在开始进行放宽限制的测试

如果你觉得你的代码需要更正的,请跟帖,跟帖更正限时一天之内
更正的代码和原来的代码只能相差最多两行并且在20字节以内,
否则更正代码视作无效


[color=0000FF]最终结果:[/color]
本题测试数据一共四个Test,能全部通过前四组的代码的作者有:
flyee (-2)
AntiMicrosoft (-1)
从速度上来说,这两份代码都很好。
从代码结构和算法上来看,两人用的思路也差不多。

所以我决定flyee和AntiMicrosoft两人同时胜出作为本次比赛的冠军

回复列表 (共42个回复)

沙发

我的代码错了。。。。不过就算回来也是TLE的。。。
#include <stdio.h>
#include <string.h>

#define  MAX_CHAR_LEN   10001

int main(void)
{
    char str1[MAX_CHAR_LEN],str2[MAX_CHAR_LEN];
    char *pMin,*pMax;
    int posFlag[MAX_CHAR_LEN];
    int bPosFlag[MAX_CHAR_LEN];
    int pos1,pos2,min;
    int aCount,bCount;

    memset(str1,0,MAX_CHAR_LEN);
    memset(str2,0,MAX_CHAR_LEN);
    memset(posFlag,0,sizeof(int)*MAX_CHAR_LEN);
    memset(bPosFlag,0,sizeof(int)*MAX_CHAR_LEN);

    while(scanf("%s %s",&str1, &str2) != EOF)
    {
        pos1 = 0,pos2 = 0;
        aCount = bCount = 0;
        while (str1[pos1] != '\0'  &&  str2 != '\0')
        {
            if (str1[pos1++] == str2[pos2++])
            {
                aCount++;
                posFlag[pos1-1] = 1;
            }
        }
        if (str1[pos1] == '\0')
        {
            min = pos1;
            pMin = str1;
            pMax = str2;
        }
        else
        {
            min = pos2;
            pMin = str2;
            pMax = str1;
        }
        for (pos1=0; pos1<min; pos1++)
        {
            if (posFlag[pos1] == 0)
            {
                for (pos2=0; pMax[pos2]!='\0'; pos2++)
                {
                    if (posFlag[pos2] == 0  &&
                        pMax[pos2] == pMin[pos1] &&
                        bPosFlag[pos2] == 0)
                    {
                        bCount++;
                        bPosFlag[pos2] = 1;
                        break;
                    }
                }
            }
        }

        printf("%dA%dB\n",aCount,bCount);
        memset(str1,0,MAX_CHAR_LEN);
        memset(str2,0,MAX_CHAR_LEN);
        memset(posFlag,0,sizeof(int)*MAX_CHAR_LEN);
        memset(bPosFlag,0,sizeof(int)*MAX_CHAR_LEN);
    }

    return 0;
}

板凳

这次比赛的时间限制是多少呀?如果为1s的话,长为10000的数组,用O(n)的算法不会TLE的吧?

3 楼

[code=c]
#include <iostream>
#include <list>
#include <algorithm>
#include <cstring>

using namespace std;
const int MAX_CHAR_LEN = 10001;

int main()
{
    char str1[MAX_CHAR_LEN],str2[MAX_CHAR_LEN];
    while(cin>>str1>>str2)
    {
        int Sz1 = int(strlen(str1));
        int Sz2 = int(strlen(str2));
        list<char> Str1(str1, str1 + Sz1);        
        list<char> Str2(str2, str2 + Sz2);
        list<char>::iterator Iter1 = Str1.begin();
        list<char>::iterator Iter2 = Str2.begin();
        int A = 0;
        while(Iter1 != Str1.end() && Iter2 != Str2.end())
        {
            if(*Iter1 == *Iter2)
            {
                ++ A;
                Iter1 = Str1.erase(Iter1);
                Iter2 = Str2.erase(Iter2);
                continue;
            }
            ++ Iter1;
            ++ Iter2;
        }
        Iter1 = Str1.begin();
        int B = 0;
        while(Iter1 != Str1.end())
        {
            Iter2 = find(Str2.begin(), Str2.end(), *Iter1);
            if(Iter2 != Str2.end())
            {
                ++ B;
                Str2.erase(Iter2);
            }
            ++ Iter1;
        }
        cout << A << "A" << B << "B" << endl;
    }
    return 0;
}
[/code]

4 楼

刚开始把ad abdd的情况直接当做ad ab处理了,太汗了。。。。。。

5 楼

哦,我的code是在G++上编译的,飞燕MM用的是什么编译器呀?

6 楼

[code=c]
/*
编译环境: Visual C++ 6.0
Language: C/C++
*/
#include <stdio.h>
#include <string.h>

#define  MAX_CHAR_LEN   10001

void MemSet(char *p, int len)
{
    long i;
    for(i = 0; i < len; i ++)
    {
        if(p[i])
            p[i] = 0;
    }
}

void Calculate(char *p1, long n1, char *p2, long n2)
{
    static char flag[MAX_CHAR_LEN] = {0};
    MemSet(flag, MAX_CHAR_LEN);
    long A, B;
    A = B = 0;
    long i, j;
    for(i = 0; i < n1; i ++)
    {
        for(j = 0; j < n2; j ++)
        {
            if(i > j && i < n2 && p1[i] == p2[i] && flag[i])
                break;
            if(i == j && !flag[i] && p1[i] == p2[i])
            {
                A ++;
                flag[i] = 1;
                break;
            }
            else if(j < i && i < n2 && !flag[i] && p1[i] == p2[i])
            {
                A ++;
                flag[i] = 1;
                break;
            }
            else if(j > i && j < n1 && !flag[j] && p1[j] == p2[j])
            {
                A ++;
                flag[j] = 1;
                continue;
            }
            else if(i != j && !flag[j] && p1[i] == p2[j])
            {
                B ++;
                flag[j] = 1;
                break;
            }
        }
    }

    printf("%ldA%ldB\n", A, B);
}

int main()
{
    char str1[MAX_CHAR_LEN], str2[MAX_CHAR_LEN];
    while(scanf("%s%s",str1, str2) != EOF)
    {
        Calculate(str1, strlen(str1), str2, strlen(str2));
    }
    
    return 0;
}
[/code]

7 楼

原来的条件错了
#include <iostream>
using namespace std;
const int MAX_CHAR_LEN = 10001;
int main()
{
    char str1[MAX_CHAR_LEN],str2[MAX_CHAR_LEN];
    while(cin>>str1>>str2)
    {
    int A=0;int B=0;
    for(int k=0;(str1[k]!='\0')||(str2[k]!='\0');++k)
    if(str1[k]==str2[k])
    ++A;
    
    for(int i=0;i<=strlen(str1)&&i<=strlen(str2);++i)
    for(int j=0;j<=strlen(str2);++j)
    {
    if(str1[i]==str2[j])
    {++B;
    break;}
    }
    B=B-A-1;
    
    cout<<A<<'A'<<B<<'B';
    }
    return 0;
}

8 楼

[quote]哦,我的code是在G++上编译的,飞燕MM用的是什么编译器呀?[/quote]
你想要指定什么编译器就什么编译器:GCC,G++,VC6,VC7,VC8,VC6++,VC7++,VC8++

9 楼

以上你们修正的代码仍然没有一份通过测试:三个是TLE,一个是WA

10 楼


...能给个没过的case吗?

我来回复

您尚未登录,请登录后再回复。点此登录或注册