Posts

Showing posts from February, 2017

【POJ】Symmetric Order

Problem  here Solution #include <iostream> #include <string> #include <vector> using namespace std ; vector < string > strs; int n, cnt = 0 ; void solve( int a, int b){ if (b == strs.size() || a == strs.size()) return ; cout << strs[a] << endl; solve(a+ 2 , b+ 2 ); if (strs[b] != " " ) cout << strs[b] << endl; } int main(){ while ( cin >> n){ strs.clear(); if (n == 0 ) break ; for ( int i = 0 ; i < n; i++){ string input; cin >> input; strs.push_back(input); } cout << "SET " << ++cnt << endl; if (n% 2 != 0 ) strs.push_back( " " ); solve( 0 , 1 ); } return 0 ; }

【USACO】Barn Repair

Problem  here Solution dp~~~ /* ID: LeongHouHeng PROG: barn1 LANG: C++ */ #include <iostream> #include <memory.h> #include <string.h> #include <fstream> #include <algorithm> using namespace std ; ifstream fin( "barn1.in" ); ofstream fout( "barn1.out" ); int cows[ 201 ]; int dp[ 250 ][ 60 ]; int MIN_NUM = 2e9 ; int main(){ int M, S, C; fin >> M >> S >> C; for ( int i = 0 ; i < C; i++){ fin >> cows[i]; } sort(cows, cows+C); memset (dp, 0x1f , sizeof (dp)); dp[ 0 ][ 0 ] = 1 ; for ( int i = 1 ; i < C; i++){ for ( int j = 0 ; j <= i && j < M; j++){ dp[i][j] = dp[i- 1 ][j] + (cows[i] - cows[i- 1 ]); if (j > 0 ) dp[i][j] = min(dp[i][j], dp[i- 1 ][j- 1 ] + 1 ); if (C- 1 == i) MIN_NUM = min(MIN_NUM, dp[i][j]); } } fo...