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: TCCC 03 Round 2 500 | February 14, 2011 @ 6:04am
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 100 #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 int mat[SIZE][SIZE],Color[SIZE],Nodes,check; void dfs(int u) { int i; REP(i,Nodes) { if(mat[u][i]) { if(Color[i]==0) { Color[i]=Color[u]*(-1); dfs(i); } else if(Color[i]==Color[u]) check=0; } } } class Marketing { public: long long howMany(vector <string> compete) { ll i,sum=1,u,v; Nodes=SZ(compete); Clear(mat,0); REP(i,Nodes) { istringstream iss(compete[i]); u=i; while(iss>>v) { mat[u][v]=mat[v][u]=1; } } Clear(Color,0); REP(i,Nodes) { if(Color[i]==0) { check=1; Color[i]=1; dfs(i); if(check) sum*=2; else return -1; } } return sum; } }; 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[] ) { Marketing objectMarketing; //test case0 vector <string> param00; param00.push_back("1 4"); param00.push_back("2"); param00.push_back("3"); param00.push_back("0"); param00.push_back(""); long long ret0 = objectMarketing.howMany(param00); long long need0 = 2; assert_eq(0,ret0,need0); //test case1 vector <string> param10; param10.push_back("1"); param10.push_back("2"); param10.push_back("0"); long long ret1 = objectMarketing.howMany(param10); long long need1 = -1; assert_eq(1,ret1,need1); //test case2 vector <string> param20; param20.push_back("1"); param20.push_back("2"); param20.push_back("3"); param20.push_back("0"); param20.push_back("0 5"); param20.push_back("1"); long long ret2 = objectMarketing.howMany(param20); long long need2 = 2; assert_eq(2,ret2,need2); //test case3 vector <string> param30; param30.push_back(""); param30.push_back(""); param30.push_back(""); param30.push_back(""); param30.push_back(""); param30.push_back(""); param30.push_back(""); param30.push_back(""); param30.push_back(""); param30.push_back(""); param30.push_back(""); param30.push_back(""); param30.push_back(""); param30.push_back(""); param30.push_back(""); param30.push_back(""); param30.push_back(""); param30.push_back(""); param30.push_back(""); param30.push_back(""); param30.push_back(""); param30.push_back(""); param30.push_back(""); param30.push_back(""); param30.push_back(""); param30.push_back(""); param30.push_back(""); param30.push_back(""); param30.push_back(""); param30.push_back(""); long long ret3 = objectMarketing.howMany(param30); long long need3 = 1073741824; assert_eq(3,ret3,need3); //test case4 vector <string> param40; param40.push_back("1"); param40.push_back("2"); param40.push_back("3"); param40.push_back("0"); param40.push_back("5"); param40.push_back("6"); param40.push_back("4"); long long ret4 = objectMarketing.howMany(param40); long long need4 = -1; assert_eq(4,ret4,need4); }
Syntax Highlighting
[
Open in new window
]
Author Comments
none
Rating
4.41 / 8
54 Votes
http://codebin.yi.org/1120
page generated in 0.01 seconds