SRM 501 DIV2悲剧

250的题,一上来看就是一个水题,但是写复杂了,208分收场

500分的题,开始以为是个简单DP,写出来发现原来可以有负数,再改分类讨论,就挂了一组数据当nB为0的时候的数据挂了……

改后的代码

SRM 501 500分
   
     
1 // BEGIN CUT HERE
2
3   // END CUT HERE
4   #line 5 "FoxPlayingGame.cpp"
5 #include < cstdlib >
6 #include < cctype >
7 #include < cstring >
8 #include < cstdio >
9 #include < cmath >
10 #include < algorithm >
11 #include < vector >
12 #include < string >
13 #include < iostream >
14 #include < sstream >
15 #include < map >
16 #include < set >
17 #include < queue >
18 #include < stack >
19 #include < fstream >
20 #include < numeric >
21 #include < iomanip >
22 #include < bitset >
23 #include < list >
24 #include < stdexcept >
25 #include < functional >
26 #include < utility >
27 #include < ctime >
28   using namespace std;
29
30   #define PB push_back
31 #define MP make_pair
32
33 #define REP(i,n) for(i=0;i<(n);++i)
34 #define FOR(i,l,h) for(i=(l);i<=(h);++i)
35 #define FORD(i,h,l) for(i=(h);i>=(l);--i)
36
37 typedef vector < int > VI;
38 typedef vector < string > VS;
39 typedef vector < double > VD;
40 typedef long long LL;
41 typedef pair < int , int > PII;
42 const double INF = 1e9;
43
44 class FoxPlayingGame
45 {
46 public :
47 const static int N = 51 ;
48
49 double dp[N][N];
50 double theMax( int nA, int nB, int paramA, int paramB)
51 {
52 double sA = paramA / 1000.0 ;
53 double sB = paramB / 1000.0 ;
54 if (sA < 0 )
55 {
56 if (sB > 1 )
57 return nA * sA;
58 else if (sB <= 1 && sB >= 0 )
59 return nA * sA * pow(sB, nB);
60 else if (sB < 0 && sB >= - 1 && nB > 0 )
61 return sB * sA * nA;
62 else if (sB < 0 && sB >= - 1 && nB == 0 )
63 return sA * nA;
64 else
65 {
66 if (nB & 1 )
67 return sA * nA * pow(sB, nB);
68 else if (nB == 0 )
69 return sA * nA;
70 else return sA * nA * pow(sB, nB - 1 );
71 }
72 }
73 else
74 {
75 if (sB > 1 )
76 return nA * sA * pow(sB, nB);
77 else if (sB <= 1 && sB >= 0 )
78 return nA * sA;
79 else if (sB < 0 && sB >= - 1 )
80 return nA * sA;
81 else
82 {
83 if ((nB & 1 ) == 0 )
84 return sA * nA * pow(sB, nB);
85 else return sA * nA * pow(sB, nB - 1 );
86 }
87 }
88 }
89
90 // BEGIN CUT HERE
91 public :
92 void run_test( int Case) { if ((Case == - 1 ) || (Case == 0 )) test_case_0(); if ((Case == - 1 ) || (Case == 1 )) test_case_1(); if ((Case == - 1 ) || (Case == 2 )) test_case_2(); if ((Case == - 1 ) || (Case == 3 )) test_case_3(); if ((Case == - 1 ) || (Case == 4 )) test_case_4(); if ((Case == - 1 ) || (Case == 5 )) test_case_5(); }
93 private :
94 template < typename T > string print_array( const vector < T > & V) { ostringstream os; os << " { " ; for (typename vector < T > ::const_iterator iter = V.begin(); iter != V.end(); ++ iter) os << ' \" ' << * iter << " \", " ; os << " } " ; return os.str(); }
95 void verify_case( int Case, const double & Expected, const double & Received) { cerr << " Test Case # " << Case << " ... " ; if (Expected == Received) cerr << " PASSED " << endl; else { cerr << " FAILED " << endl; cerr << " \tExpected: \" " << Expected << ' \" ' << endl; cerr << " \tReceived: \" " << Received << ' \" ' << endl; } }
96 void test_case_0() { int Arg0 = 5 ; int Arg1 = 4 ; int Arg2 = 3000 ; int Arg3 = 2000 ; double Arg4 = 240.0 ; verify_case( 0 , Arg4, theMax(Arg0, Arg1, Arg2, Arg3)); }
97 void test_case_1() { int Arg0 = 3 ; int Arg1 = 3 ; int Arg2 = 2000 ; int Arg3 = 100 ; double Arg4 = 6.0 ; verify_case( 1 , Arg4, theMax(Arg0, Arg1, Arg2, Arg3)); }
98 void test_case_2() { int Arg0 = 4 ; int Arg1 = 3 ; int Arg2 = - 2000 ; int Arg3 = 2000 ; double Arg4 = - 8.0 ; verify_case( 2 , Arg4, theMax(Arg0, Arg1, Arg2, Arg3)); }
99 void test_case_3() { int Arg0 = 5 ; int Arg1 = 5 ; int Arg2 = 2000 ; int Arg3 = - 2000 ; double Arg4 = 160.0 ; verify_case( 3 , Arg4, theMax(Arg0, Arg1, Arg2, Arg3)); }
100 void test_case_4() { int Arg0 = 50 ; int Arg1 = 50 ; int Arg2 = 10000 ; int Arg3 = 2000 ; double Arg4 = 5.62949953421312E17 ; verify_case( 4 , Arg4, theMax(Arg0, Arg1, Arg2, Arg3)); }
101 void test_case_5() { int Arg0 = 41 ; int Arg1 = 34 ; int Arg2 = 9876 ; int Arg3 = - 1234 ; double Arg4 = 515323.9982341775 ; verify_case( 5 , Arg4, theMax(Arg0, Arg1, Arg2, Arg3)); }
102
103 // END CUT HERE
104
105 };
106
107 // BEGIN CUT HERE
108 int main()
109 {
110 FoxPlayingGame ___test;
111 ___test.run_test( - 1 );
112 return 0 ;
113 }
114 // END CUT HERE

PS 500分的题其实非常简单……

cai学长的代码

SRM 501 500分 by perfectCai
   
     
1 double theMax( int nA, int nB, int paramA, int paramB)
2 {
3 int i;
4 double ans, temp;
5
6 ans = nA * paramA / 1000.0 ;
7 temp = ans;
8 for (i = 0 ; i < nB; i ++ )
9 {
10 temp *= paramB / 1000.0 ;
11 ans = max(ans, temp);
12 }
13
14 return ans;
15 }

1000分的题更是悲剧到极点了。

由于500分浪费了太多时间1000的题没写完,赛后过了……一个赤裸裸的DP,写的有点着急了。错误百出。

TC的服务器很快40^5的复杂度可以秒杀。

本来指望这次进DIV1玩玩的……哎,继续混吧……

SRM 501 1000分
   
     
1 const int SIZE = 41 ;
2 long long dp[SIZE][SIZE][ 2 ][ 1600 + 1 ];
3 class FoxAverageSequence
4 {
5 public :
6
7 const static int MOD = 1000000007 ;
8
9 int theCount(vector < int > seq)
10 {
11 memset(dp, 0 , sizeof (dp)); // 1 表示递减
12 if (seq[ 0 ] == - 1 )
13 {
14 for ( int i = 0 ;i <= 40 ;i ++ )
15 dp[ 0 ][i][ 0 ][i] ++ ;
16 }
17 else
18 dp[ 0 ][seq[ 0 ]][ 0 ][seq[ 0 ]] ++ ;
19 long long ans = 0 ;
20 for ( int i = 1 ;i < seq.size();i ++ )
21 {
22 for ( int j = 0 ;j <= 40 ;j ++ ) // i
23 {
24 bool flag = true ;
25 if (seq[i] != - 1 )
26 {
27 flag = false ;
28 j = seq[i];
29 }
30 for ( int k = 0 ;k <= 40 ;k ++ ) // i - 1
31 {
32 for ( int s = 0 ;s <= 40 * i;s ++ )
33 {
34 if (i * j > s)
35 continue ;
36 if (j < k)
37 dp[i][j][k > j][s + j] = (dp[i][j][k > j][s + j] + dp[i - 1 ][k][ 0 ][s]) % MOD ;
38 else
39 {
40 dp[i][j][k > j][s + j] = (dp[i][j][k > j][s + j] + dp[i - 1 ][k][ 0 ][s]) % MOD;
41 dp[i][j][k > j][s + j] = (dp[i][j][k > j][s + j] + dp[i - 1 ][k][ 1 ][s]) % MOD;
42 }
43 }
44 }
45 if ( ! flag)
46 break ;
47 }
48 }
49 for ( int i = 0 ;i <= 40 ;i ++ )
50 {
51 for ( int j = 0 ;j <= 40 * 40 ;j ++ )
52 {
53 ans = (ans + dp[seq.size() - 1 ][i][ 0 ][j]) % MOD;
54 ans = (ans + dp[seq.size() - 1 ][i][ 1 ][j]) % MOD;
55 }
56 }
57 return ans;
58 }
59
60 // BEGIN CUT HERE
61 public :
62 void run_test( int Case)
63 {
64 if ((Case == - 1 ) || (Case == 0 )) test_case_0();
65 if ((Case == - 1 ) || (Case == 1 )) test_case_1();
66 if ((Case == - 1 ) || (Case == 2 )) test_case_2();
67 if ((Case == - 1 ) || (Case == 3 )) test_case_3();
68 if ((Case == - 1 ) || (Case == 4 )) test_case_4();
69 }
70 private :
71 template < typename T > string print_array( const vector < T > & V)
72 {
73 ostringstream os;
74 os << " { " ;
75 for (typename vector < T > ::const_iterator iter = V.begin(); iter != V.end(); ++ iter) os << ' \" ' << * iter << " \", " ;
76 os << " } " ;
77 return os.str();
78 }
79 void verify_case( int Case, const int & Expected, const int & Received)
80 {
81 cerr << " Test Case # " << Case << " ... " ;
82 if (Expected == Received) cerr << " PASSED " << endl;
83 else
84 {
85 cerr << " FAILED " << endl;
86 cerr << " \tExpected: \" " << Expected << ' \" ' << endl;
87 cerr << " \tReceived: \" " << Received << ' \" ' << endl;
88 }
89 }
90 void test_case_0()
91 {
92 int Arr0[] = { 3 , - 1 };
93 vector < int > Arg0(Arr0, Arr0 + ( sizeof (Arr0) / sizeof (Arr0[ 0 ])));
94 int Arg1 = 4 ;
95 verify_case( 0 , Arg1, theCount(Arg0));
96 }
97 void test_case_1()
98 {
99 int Arr0[] = { 5 , 3 , - 1 };
100 vector < int > Arg0(Arr0, Arr0 + ( sizeof (Arr0) / sizeof (Arr0[ 0 ])));
101 int Arg1 = 2 ;
102 verify_case( 1 , Arg1, theCount(Arg0));
103 }
104 void test_case_2()
105 {
106 int Arr0[] = { - 1 , 0 , 40 };
107 vector < int > Arg0(Arr0, Arr0 + ( sizeof (Arr0) / sizeof (Arr0[ 0 ])));
108 int Arg1 = 0 ;
109 verify_case( 2 , Arg1, theCount(Arg0));
110 }
111 void test_case_3()
112 {
113 int Arr0[] = { - 1 , 40 , - 1 , - 1 , - 1 , 10 , - 1 , - 1 , - 1 , 21 , - 1 };
114 vector < int > Arg0(Arr0, Arr0 + ( sizeof (Arr0) / sizeof (Arr0[ 0 ])));
115 int Arg1 = 579347890 ;
116 verify_case( 3 , Arg1, theCount(Arg0));
117 }
118 void test_case_4()
119 {
120 int Arr0[] = { - 1 , 12 , 25 , 0 , 18 , - 1 };
121 vector < int > Arg0(Arr0, Arr0 + ( sizeof (Arr0) / sizeof (Arr0[ 0 ])));
122 int Arg1 = 58 ;
123 verify_case( 4 , Arg1, theCount(Arg0));
124 }
125
126 // END CUT HERE
127
128 };

你可能感兴趣的:(div)