It’s a bottom up dp approach. #include <iostream> #include <cstdio> #include <queue> #include <sstream> #include <string> #include <queue> #include <vector> #include <cstring> #include <algorithm> #include <cmath> #define INF 100000000 using namespace std; vector<int> vb[11]; vector<int> v; int dp[11][1010]; void init() { for(int i=0;i<11;i++) { vb[i].clear(); for(int j=0;j<1010;j++) { dp[i][j]=-1; } } } int _min(int a,int
Month: November 2015
11450
It’s a bottom up approach. #include <iostream> #include <cstdio> #include <cstring> #include <string> #include <algorithm> #include <vector> #define INF 100000000 using namespace std; int MX; vector<int> vb[21]; int dp[201][21]; void init() { for(int i=0;i<21;i++) vb[i].clear(); MX = INF; for(int i=0;i<201;i++) for(int j=0;j<21;j++) { if(j==0) dp[i][j]=0; else dp[i][j]=-1;//not solved } } int _max(int a,int b) {
11122
It took me long time to get accepted. Needs some geometric knowledge, used graham scan algorithm, can be done also without using that, but most importantly made me crazy to figure out the special cases. So the coding was not well formatted. Adding some special input cases for the problem. #include <iostream> #include <cstdio> #include
10102
Critical t get the question but easy to solve. Problem asks to find the maximum length of minimum distance. #include <iostream> #include <cstdio> #include <vector> #include <stack> #include <cmath> #include <cstring> #include <fstream> #include <string> #include <algorithm> #define INF 100000000 #define ll long long using namespace std; struct Cord{ int x,y; }; int M; char
10336
#include <iostream> #include <cstdio> #include <vector> #include <stack> #include <queue> #include <cmath> #include <cstring> #include <fstream> #include <string> #include <algorithm> #define INF 1000000000 #define ll long long using namespace std; int h,w; string arr[1010]; bool visit[1010][1010]; int stateCount[26]; struct stateInfo{ int count; int name; }; vector<stateInfo> vb; bool cmp(stateInfo a,stateInfo b) { if(a.count!=b.count) return a.count>b.count;
11364
#include <iostream> #include <cstdio> #include <vector> #include <stack> #include <cmath> #include <cstring> #include <string> #include <algorithm> #define INF 1000000000 #define ll long long using namespace std; vector<int> vb; int main() { int t,n,a; ll dist; scanf("%d",&t); while(t–) { scanf("%d",&n); vb.clear(); for(int i=0;i<n;i++) { scanf("%d",&a); vb.push_back(a); } sort(vb.begin(),vb.end()); dist=0; for(int i=1;i<n;i++) dist+=(vb[i]-vb[i-1]); dist+=(vb[n-1]-vb[0]); printf("%lld\n",dist); } return
11661
#include <iostream> #include <cstdio> #include <sstream> #include <string> #include <cstring> using namespace std; char s[2000000+10]; int main() { int n,dist,prev_idx; char prev; bool first; while(scanf("%d",&n),n) { dist= n; first=0; scanf("%s",s); for(int i=0;i<n;i++) { //scanf("%c",&s[i]); if(s[i]=='Z') dist=0; if(s[i]=='R' && first==false) { prev='R'; prev_idx=i; first=true; continue; } if(s[i]=='D' && first==false) { prev='D'; prev_idx=i; first=true; continue; } if(first==1
112
Tree Summing. #include <iostream> #include <cstdio> #include <sstream> #include <string> using namespace std; int I; string str; int next_index; bool PATHFOUND; bool isEmpty(int a,int b) { if(a+1==b && str[a]=='(' && str[b]==')') return 1; return 0; } int findnum(int idx) { int numfoundAt=-1; int num=0; bool negative=false; for(int i=idx;i<str.size();i++) { if(str[i]!='(' && str[i]!=')') { numfoundAt =
1225
#include <iostream> #include <cstdio> #include <vector> #include <queue> #include <sstream> #include <string> #include <cstring> #include <cmath> #define ll long long using namespace std; ll digitCount[10]; ll pwr; ll numberOfDigit[15];//total count of i digit numbers int getLength(int a) { if(a<10) { pwr=1; return 1; } int len=0; pwr=1; while(a) { len+=1; a/=10; pwr*=10; } pwr/=10;//10 to
521
#include <iostream> #include <cstdio> #include <vector> #include <queue> #include <sstream> #include <string> #include <cstring> #include <cmath> using namespace std; int n,d,s; int BusStartAtStop[51]; int BusRunAtRoad[51]; int gr[31][31]; bool visit[51][51]; vector<int> vRoadstops[21]; vector<int> vBusRunAtRoad[21]; void init() { for(int i=0;i<51;i++) { BusStartAtStop[i]=0; BusRunAtRoad[i]=0; } for(int i=0;i<31;i++) for(int j=0;j<31;j++) gr[i][j]=0; for(int i=0;i<21;i++) { vRoadstops[i].clear(); vBusRunAtRoad[i].clear(); } } void