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
Category: Programming Problem
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
794
This one took me a looong time to figure out the solution, i used dynamic programming approach to modify the bfs traversal. #include <iostream> #include <cstdio> #include <cstdlib> #include <vector> #include <cstring> #include <fstream> #include <string> #include <map> #include <queue> #define INF 100000000 //#define ll long long #define PASS 2 #define NEED 1 #define NONEED
710
This is quite an easy problem. But it took me long time to realize that to determine the number of total game segments is nothing but counting the direction changes to reach the destination. #include <iostream> #include <cstdio> #include <climits> #include <queue> #include <cstring> #include <string> using namespace std; int w,h; int SEGMENT; int gr[80][80];