1 min read

Categories

  • 技术

时间:2007-08-07 成绩:1417.24(233.89/250 + 440.09/500 + 743.26/1000) 排名:3/75 第一名成绩:1461.03

代码: 250

#include <vector>
#include <iostream>
using namespace std; 
class BestHotel{

    public:
        int numberOfDisadvantageous(vector <int> price, vector <int> quality){
            int ret = 0;
            for (int i = 0; i < price.size(); i ++){
                for (int j = 0; j < price.size(); j ++){
                    if (j != i){
                        if ((price[j] <= price[i] && quality[j] > quality[i]) || (price[j] < price[i] && quality[j] >= quality[i])){
                            ret ++;
                            break;
                        }
                    }
                }
            }
           
            return ret;
        }

}; 

500

#include <iostream>
using namespace std; 
typedef long long int UINT; 
UINT get_count(int len){

    UINT mn = 1, mx = 9;
    for (int i = 1; i < len; i ++){
        mn *= 10;
        mx = mx * 10 + 9;
    }
    return (mx - mn + 1) * len;

}
class BooksNumbering{

    public:
         int numberOfBooks(int usedDigits){
             UINT n = usedDigits;
             int i;
             for (i = 1; i <= 10; i ++){
                 if (get_count(i) < n) n -= get_count(i);
                 else break;
             }
             
             if (n % i != 0) return -1;
             else {
                 int ret = 1;
                 for (int j = 1; j < i; j ++) ret *= 10;
                 ret += int(n / i) - 1;
                 return ret;
             }
         }

};

1000

#include <vector>
#include <iostream>
using namespace std; 
#define ADD 20000
int dp[ADD * 2 + 1], dp_x[ADD * 2 + 1]; 
class SumoTournament{

    public:
        int maxWeight(vector <int> weight, int averageWeight){
            for (int i = 0; i < weight.size(); i ++) weight[i] -= averageWeight;
            memset(dp, 255, sizeof(dp));
            memset(dp_x, 255, sizeof(dp_x));
            dp[ADD] = dp_x[ADD] = 0;
            for (int i = 0; i < weight.size(); i ++){
                for (int j = 0; j <= ADD * 2; j ++){
                    if (dp[j] != -1){
                        dp_x[j + weight[i]] = max(dp_x[j + weight[i]], max(dp[j], weight[i] + averageWeight));
                    }
                }
                memcpy(dp, dp_x, sizeof(dp));
            }          
            if (dp[ADD] == 0) return -1;
            else return dp[ADD];
        }

};