赵斌

赵斌的博客

他的个人主页  他的博客

POJ 3425

赵斌  2009年08月15日 星期六 01:12 | 1048次浏览 | 0条评论

原文通过blogbus2zeuux工具同步发布:http://antmanler.blogbus.com/logs/43837404.html

文章发布时间:2009/8/9/10/49

心血来潮,在POJ上小试一题,结果不好: AC 224K 16ms...

/*
*@summery: POJ problem id : 3245
*@author: antmanler
*2009.08.09
*/

#include <iostream>
#include <map>

using namespace std ;

typedef map < int , int > Questions ;

int main () {
   
    Questions qst ;
    int cnt = 0 , total = 0 , cans = 0 ;
   
    cin >> cnt ;
   
    for ( int i = 0 ; i < cnt ; i ++ ){
        int q = - 1 , a = 0 , x = 0 ;
        cin >> q >> a >> x ;
        Questions :: iterator pos = qst . find ( q ) ;
        if ( pos == qst . end () && a != 0 ) {
            qst . insert ( make_pair ( q , a )) ;
        } else {
            cans += a ;
        }
        total += ( 10 + ( a ? ( a * ( 10 + x * 20 )) : 0 )) ;
    }
   
    total += 10 * cans ;
   
    cout << total << endl ;
   
    return 0 ;
}
实在太不满意了,优化了一下,又提交了一次: AC 224K 0ms

/*
*@summery: POJ problem id : 3245
*@author: antmanler
*2009.08.09
*/

#include <iostream>
#include <set>
using namespace std ;
typedef set < int > Questions ;
int main () {
    Questions qst ;
    int cnt = 0 , total = 0 , cans = 0 , q = - 1 , a = 0 , x = 0 ;
    cin >> cnt ;
    for ( int i = 0 ; i < cnt ; i ++ ){
        cin >> q >> a >> x ;
        Questions :: iterator pos = qst . find ( q ) ;
        if ( pos == qst . end () && a != 0 ) {
            qst . insert ( q ) ;
        } else {
            cans += a ;
        }
        switch ( ( a << 1 )| x ) {
            case 2 : total += 20 ; break ;
            case 3 : total += 40 ; break ;
            default : total += 10 ;
        }
    }
    total += 10 * cans ;
    cout << total << endl ;
    return 0 ;
}

评论

我的评论:

发表评论

请 登录 后发表评论。还没有在Zeuux哲思注册吗?现在 注册 !

暂时没有评论

Zeuux © 2024

京ICP备05028076号