2009-12-13から1日間の記事一覧

PKU 1020 Anniversary Cake

PKU

Anniversary Cakeバックトラック。余りが出ないようにという条件があるので、各深さでは最初に見つけたケーキの残りを切り取ればよい。 #include <iostream> #include <numeric> using namespace std; int s; // ケーキサイズ bool cake[99][99]; // ケーキ int piece[11]; // </numeric></iostream>…

PKU 1019 Number Sequence

PKU

Number Sequence入力 i に対して、i が含まれるグループを Sk とすると、k もグループ Sk の長さ |Sk| も O(√i) 程度である。x の桁数を digit(x) として、 |Sx| = |Sx-1| + digit(x)が成り立つことから k を求める。グループ1つに対してならば n 番目の数…

PKU 1018 Communication System

PKU

Communication System帯域幅を変えながら、その帯域幅以上で最安の製品を選んでいく。 #include <iostream> #include <vector> using namespace std; struct MAN { int B, P; }; int main() { int t; cin >> t; for ( int i=0; i<t; i++ ) { // 読み込み int n; cin >> n; vector<vector<MAN> > man( n ); for ( int j=0; j<n; j++ ) { int m; cin >> m; </n;></vector<man></t;></vector></iostream>…

PKU 1021 2D-Nim

PKU

2D-Nim #include <iostream> #include <vector> #include <algorithm> using namespace std; struct XY { int x, y; XY() {} XY( int x_, int y_ ) : x(x_), y(y_) {} bool operator<( const XY &a ) const { return x</algorithm></vector></iostream>