The Code-Bin
Links
Home
Add your code!
All Listings
About
Latest Entry
Featured Scripts
Author's Website
Latest Entries
FFMPEG Thumbnail Scr...
PHP, 0.8KB
Jul. 29, 10:24pm
John
Z80 Assembler, 190 bytes
Feb. 17, 3:36am
John
Z80 Assembler, 176 bytes
Sep. 13, 2:19am
John
Z80 Assembler, 77 bytes
Sep. 13, 2:18am
John
Z80 Assembler, 209 bytes
Sep. 13, 2:17am
untitled C++ Code
Posted by: SRM 340 Div 2 1000 | February 13, 2011 @ 8:25am
C++ Code
[
Download
]
/* FORHAD-SUST-BD */ #include <iostream> #include <string> #include <map> #include <queue> #include <stack> #include <algorithm> #include <list> #include <set> #include <cmath> #include <cstring> #include <stdio.h> #include <string.h> #include <sstream> #include <stdlib.h> #include <vector> #include <iomanip> using namespace std; #ifdef __GNUC__ typedef long long ll;typedef unsigned long long ull; #else typedef __int64 ll; typedef unsigned __int64 ull; #endif #define INF 1<<28 #define SIZE 55 #define PI 2*acos(0) #define fg %I64d #define REP(i,n) for (i=0;i<n;i++) #define REV(i,n) for (i=n;i>=0;i--) #define FOR(i,p,k) for (i=p; i<k;i++) #define FOREACH(it,x) for(__typeof((x).begin()) it=(x.begin()); it!=(x).end(); ++it) #define bug(x) cout<< "->" <<#x<<": "<<x<<endl #define Sort(x) sort(x.begin(),x.end()) #define Reverse(x) reverse(x.begin(),x.end()) #define MP(a,b) make_pair(a,b) #define Clear(x,with) memset(x,with,sizeof(x)) #define Copy(c,r) memcpy(c,r,sizeof(r)) #define SZ(x) (int)x.size() #define length(x) (int)x.length() #define All(x) x.begin(),x.end() #define pb push_back #define popcount(i) __builtin_popcount(i) #define gcd(a,b) __gcd(a,b) #define fs first #define sc second #define two(X) (1<<(X)) #define twoL(X) (((int64)(1))<<(X)) #define contain(S,X) (((S)&two(X))!=0) #define containL(S,X) (((S)&twoL(X))!=0) typedef pair<int,int> pii; typedef pair<double,double> pdd; typedef vector<int> vi; typedef vector<double>vd; typedef vector<ll>vll; typedef vector<string> vs; typedef vector<vi>vvi; typedef vector<vll>vvll; typedef vector<vd>vvd; typedef vector<pii>vpii; typedef map<string,int> msi; typedef map<int,int>mii; typedef map<pii,int>mpi; template<class T> inline T sqr(T x){return x*x;} template<class T> inline bool isPrime(T n){if(n<=1)return false;for (T i=2;i*i<=n;i++) if (n%i==0) return false;return true;} template<class T> inline T Mod(T n,T m) {return (n%m+m)%m;} //For Positive Negative No. template<class T> string toString(T n){ostringstream oss;oss<<n;oss.flush();return oss.str();} int toInt(string s){int r=0;istringstream sin(s);sin>>r;return r;} ll toLl(string s){ll r=0;istringstream sin(s); sin>>r; return r;} template<class T> void debug(const T& e){cout<<e<<endl;} template<class T1,class T2> void debug(const T1& e1,const T2& e2){cout<<e1<<"\t"<<e2<<endl;} template<class T1,class T2,class T3> void debug(const T1& e1,const T2& e2,const T3& e3){cout<<e1<<"\t"<<e2<<"\t"<<e3<<endl;} template<class T1,class T2,class T3,class T4> void debug(const T1& e1,const T2& e2,const T3& e3,const T4& e4){cout<<e1<<"\t"<<e2<<"\t"<<e3<<"\t"<<e4<<endl;} template<class T1,class T2,class T3,class T4,class T5> void debug(const T1& e1,const T2& e2,const T3& e3,const T4& e4,const T5& e5){cout<<e1<<"\t"<<e2<<"\t"<<e3<<"\t"<<e4<<"\t"<<e5<<endl;} template<class T> void debug(vector<T>& e){int i;REP(i,SZ(e)) cout<<e[i]<<" ";cout<<endl;} template<class T> void debug(vector< basic_string<T> >& e){int i,j;REP(i,SZ(e)) {REP(j,SZ(e[i])) cout<<e[i][j];cout<<endl;} cout<<endl;} template<class T> void debug(vector< vector<T> >& e){int i,j;REP(i,SZ(e)) {REP(j,SZ(e[i])) cout<<e[i][j]<<"\t";cout<<endl;} cout<<endl;} template<class T> void debug(T e[SIZE][SIZE],int row,int col){int i,j;REP(i,row) {REP(j,col) cout<<e[i][j]<<" ";cout<<endl;}} ll Pow(ll B,ll P){ ll R=1; while(P>0) {if(P%2==1) R=(R*B);P/=2;B=(B*B);}return R;} //compute b^p //struct pq{ int cost,node;bool operator<(const pq &b)const{return cost>b.cost;}};// Min Priority Queue //bool comp(pq a,pq b){ return a.cost > b.cost;} //Comp Sort //int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction //int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction //int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction vi tv,pv,expire,ans; int N,SkillBound; int dp[SIZE][SIZE][SIZE]; int rec(int tskill,int pskill,int month) { int &ret=dp[tskill][pskill][month],i; if(ret!=-1) return ret; if(tskill>=SkillBound && pskill >=SkillBound) return 0; ret=INF; REP(i,N) { if(tskill+1>=tv[i] && pskill+1>=pv[i] && month<expire[i]) { ret=min(ret,rec(max(tskill,tv[i]),max(pskill,pv[i]),month+1)+1); } } return ret; } void Print(int tskill,int pskill,int month) { int ret=dp[tskill][pskill][month],i; if(tskill>=SkillBound && pskill >=SkillBound) return ; REP(i,N) { if(tskill+1>=tv[i] && pskill+1>=pv[i] && month<expire[i]) { if(ret == rec(max(tskill,tv[i]),max(pskill,pv[i]),month+1)+1) { ans.pb(i); Print(max(tskill,tv[i]),max(pskill,pv[i]),month+1); return ; } } } } class CsCourses { public: vector <int> getOrder(vector <int> theoreticalValue, vector <int> practicalValue, vector <int> expir, int skillBound) { int res; ans.clear(); N=SZ(theoreticalValue); tv=theoreticalValue; pv=practicalValue; expire=expir; SkillBound=skillBound; Clear(dp,-1); res=rec(0,0,0); if(res>=INF) return ans; Print(0,0,0); return ans; } }; template<typename T> void print( T a ) { cerr << a; } void print( long long a ) { cerr << a << "L"; } void print( string a ) { cerr << '"' << a << '"'; } template<typename T> void print( vector<T> a ) { cerr << "{"; for ( int i = 0 ; i != a.size() ; i++ ) { if ( i != 0 ) cerr << ", "; print( a[i] ); } cerr << "}" << endl; } template<typename T> void assert_eq( int n, T have, T need ) { if ( have == need ) { cerr << "Case " << n << " passed." << endl; } else { cerr << "Case " << n << " failed: expected "; print( need ); cerr << " received "; print( have ); cerr << "." << endl; } } template<typename T> void assert_eq( int n, vector<T> have, vector<T> need ) { if( have.size() != need.size() ) { cerr << "Case " << n << " failed: returned " << have.size() << " elements; expected " << need.size() << " elements."; print( have ); print( need ); return; } for( int i= 0; i < have.size(); i++ ) { if( have[i] != need[i] ) { cerr << "Case " << n << " failed. Expected and returned array differ in position " << i << "."; print( have ); print( need ); return; } } cerr << "Case " << n << " passed." << endl; } void assert_eq( int n, string have, string need ) { if ( have == need ) { cerr << "Case " << n << " passed." << endl; } else { cerr << "Case " << n << " failed: expected "; print( need ); cerr << " received "; print( have ); cerr << "." << endl; } } int main( int argc, char* argv[] ) { CsCourses objectCsCourses; //test case0 vector <int> param00; param00.push_back(1); vector <int> param01; param01.push_back(1); vector <int> param02; param02.push_back(1); int param03 = 1; vector <int> ret0 = objectCsCourses.getOrder(param00,param01,param02,param03); vector <int> need0; need0.push_back(0); assert_eq(0,ret0,need0); //test case1 vector <int> param10; param10.push_back(1); param10.push_back(2); param10.push_back(1); vector <int> param11; param11.push_back(2); param11.push_back(1); param11.push_back(1); vector <int> param12; param12.push_back(5); param12.push_back(5); param12.push_back(5); int param13 = 2; vector <int> ret1 = objectCsCourses.getOrder(param10,param11,param12,param13); vector <int> need1; need1.push_back(2); need1.push_back(0); need1.push_back(1); assert_eq(1,ret1,need1); //test case2 vector <int> param20; param20.push_back(1); param20.push_back(2); param20.push_back(1); vector <int> param21; param21.push_back(2); param21.push_back(1); param21.push_back(1); vector <int> param22; param22.push_back(1); param22.push_back(1); param22.push_back(1); int param23 = 2; vector <int> ret2 = objectCsCourses.getOrder(param20,param21,param22,param23); vector <int> need2; assert_eq(2,ret2,need2); //test case3 vector <int> param30; param30.push_back(1); param30.push_back(2); param30.push_back(1); vector <int> param31; param31.push_back(2); param31.push_back(1); param31.push_back(1); vector <int> param32; param32.push_back(3); param32.push_back(2); param32.push_back(1); int param33 = 2; vector <int> ret3 = objectCsCourses.getOrder(param30,param31,param32,param33); vector <int> need3; need3.push_back(2); need3.push_back(1); need3.push_back(0); assert_eq(3,ret3,need3); //test case4 vector <int> param40; param40.push_back(1); param40.push_back(2); param40.push_back(3); param40.push_back(4); param40.push_back(5); param40.push_back(6); param40.push_back(7); vector <int> param41; param41.push_back(1); param41.push_back(2); param41.push_back(3); param41.push_back(4); param41.push_back(5); param41.push_back(6); param41.push_back(7); vector <int> param42; param42.push_back(1); param42.push_back(2); param42.push_back(3); param42.push_back(4); param42.push_back(5); param42.push_back(6); param42.push_back(7); int param43 = 7; vector <int> ret4 = objectCsCourses.getOrder(param40,param41,param42,param43); vector <int> need4; need4.push_back(0); need4.push_back(1); need4.push_back(2); need4.push_back(3); need4.push_back(4); need4.push_back(5); need4.push_back(6); assert_eq(4,ret4,need4); //test case5 vector <int> param50; param50.push_back(0); param50.push_back(1); param50.push_back(2); param50.push_back(2); param50.push_back(1); vector <int> param51; param51.push_back(0); param51.push_back(0); param51.push_back(1); param51.push_back(2); param51.push_back(1); vector <int> param52; param52.push_back(9); param52.push_back(9); param52.push_back(9); param52.push_back(9); param52.push_back(9); int param53 = 2; vector <int> ret5 = objectCsCourses.getOrder(param50,param51,param52,param53); vector <int> need5; need5.push_back(4); need5.push_back(3); assert_eq(5,ret5,need5); }
Syntax Highlighting
[
Open in new window
]
Author Comments
none
Rating
4.55 / 8
56 Votes
http://codebin.yi.org/1115
page generated in 0.01 seconds