回 帖 发 新 帖 刷新版面

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

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

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

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


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

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

回复列表 (共42个回复)

11 楼

[quote]以上你们修正的代码仍然没有一份通过测试:三个是TLE,一个是WA[/quote]
时间限制是多少?

12 楼

时间限制100ms

13 楼

[quote]
...能给个没过的case吗?
[/quote]
你的代码TLE

14 楼


100ms的话要大规模的改算法了。。。。。

15 楼

another try
[code=c]
#include <iostream>
#include <cstring>

using namespace    std;
const int MAX_CHAR_LEN = 10001;

void solve(string str1, string str2)
{
    int a=0,b=0,marks[300],len=min(str2.size(),str1.size());
    memset(marks,0,sizeof(marks));
    for(int i=0; i<len; i++){
        if(str1[i]==str2[i]){
            a++;
        }else{
            if(marks[str1[i]]<0){
                b++;
            }
            marks[str1[i]]++;
            if(marks[str2[i]]>0){
                b++;
            }
            marks[str2[i]]--;
        }
    }
    for(int i=len;i<str1.size();i++){
        if(marks[str1[i]]<0){
            b++;
        }
        marks[str1[i]]++;
    }
    for(int i=len;i<str2.size();i++){
        if(marks[str2[i]]>0){
            b++;
        }
        marks[str2[i]]--;
    }
    cout<<a<<'A'<<b<<'B'<<endl;
}

int    main()
{
    char str1[MAX_CHAR_LEN],str2[MAX_CHAR_LEN];
    while(cin>>str1>>str2)
    {
        //这里写你的计算代码
        solve(str1,str2);
    }
    return 0;
}

[/code]

16 楼

Name: "[color=Blue]flyee[/color]" Problem ID "[color=Blue]43[/color]"
Submit Time: 2007/7/31-14:29

[font=宋体][color=red]G++: Compile Warning:
Line  In function `void solve(std::string, std::string)':
Line 15: warning: array subscript has type `char'
Line 18: warning: array subscript has type `char'
Line 19: warning: array subscript has type `char'
Line 22: warning: array subscript has type `char'
Line 25: warning: comparison between signed and unsigned integer expressions
Line 26: warning: array subscript has type `char'
Line 29: warning: array subscript has type `char'
Line 31: warning: comparison between signed and unsigned integer e...[/color]
Test 1:    [color=blue]Accepted[/color]    Time = 0 ms
Test 2:    [color=blue]Accepted[/color]    Time = 10 ms
Test 3:    [color=blue]Accepted[/color]    Time = 31 ms
Test 4:    [color=red]Time Limit Exceed[/color]
────────────────
Problem ID     43
Test Result    [color=red]Time Limit Exceed[/color]
Total Time     Null
Total Memory   224 Kb
Code Length    1050 Bytes
[/font]

17 楼

[quote]Name: "[color=Blue]flyee[/color]" Problem ID "[color=Blue]43[/color]"
Submit Time: 2007/7/31-14:29

[font=宋体][color=red]
────────────────
Problem ID     43
Test Result    [color=red]Time Limit Exceed[/color]
Total Time     Null
Total Memory   224 Kb
Code Length    1050 Bytes
[/font][/quote]

O(N)都tle,你太坏了 T_T

18 楼

从c++改成c不知会不会快一点点……

[code=c]
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

const int MAX_CHAR_LEN = 10001;

void solve(char* str1, char* str2)
{
    int a=0,b=0,marks[300],i;
    memset(marks,0,sizeof(marks));
    for(i=0; str1[i]&&str2[i]; i++){
        if(str1[i]==str2[i]){
            a++;
        }else{
            if(marks[str1[i]]<0){
                b++;
            }
            marks[str1[i]]++;
            if(marks[str2[i]]>0){
                b++;
            }
            marks[str2[i]]--;
        }
    }
    if( str2[i] == 0 ){
        while( str1[i] ){
            if(marks[str1[i]]<0){
                b++;
            }
            marks[str1[i]]++;
            i++;
        }
    }else{
        while( str2[i] ){
            if(marks[str2[i]]>0){
                b++;
            }
            marks[str2[i]]--;
            i++;
        }
    }
    printf("%dA%dB\n",a,b);
}

int    main()
{
    char str1[MAX_CHAR_LEN],str2[MAX_CHAR_LEN];
    while(scanf("%s%s",str1,str2)==2)
    {
        //这里写你的计算代码
        solve(str1,str2);
    }
    return 0;
}


[/code]

19 楼

难道测试的案例中 有字符不在0~127范围内?

20 楼

[quote]难道测试的案例中 有字符不在0~127范围内?[/quote]
我没有讲一定是半角字符,还有,题目上的串长是10000,谢谢

我来回复

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