10465

#include <iostream> #include <cstdio> #include <fstream> #define INF 100000000 #define ll long long using namespace std; int m,n,MX; int main() { int tt; ll dp; int MN_Rem,MXR; while(scanf("%d%d%d",&m,&n,&tt)!=EOF) { if(m>tt && n>tt) { cout<<0<<" "<<tt<<"\n"; continue; } MX =0; bool f =false; MN_Rem = INF; MXR = 0; for(int i=0;i<=10005;i++) { for(int j=0;j<=10005;j++) { dp

793

#include <iostream> #include <string.h> #include <vector> #include <cstdio> #define SZ 1000001 using namespace std; int par[SZ]; void init() { for(int i=0;i<SZ;i++) par[i]=i; } int find(int a) { if(par[a]==a) return a; else return find(par[a]); } int main() { int t; int n,a,b; int Ycnt,Ncnt; char cmnd,ch; bool f=false; cin>>t; getchar(); while(t–) { cin>>n; init(); getchar(); Ycnt=0;

280

This also can be solved using bfs or dfs. #include <iostream> #include <string.h> #include <vector> #define INF 1000000000 using namespace std; int gr[105][105]; int n,from,to; int tt; vector<int> vb; void init() { for(int i=0;i<105;i++) for(int j=0;j<105;j++) { gr[i][j]=INF; } } void floyd() { for(int k=1;k<=n;k++) { for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) { if(gr[i][j]>gr[i][k]+gr[k][j]) gr[i][j] = gr[i][k]+gr[k][j];

10313

#include <iostream> #include <string> #include <sstream> #define ll long long using namespace std; ll ways[400][400]; ll findways(int a,int b) { ll r=0; if(ways[a][b]!=-1) return ways[a][b]; if(a==0) return 1; else { r = 0; for(int i=b;i>=1;i–) if(a-i>=0) { r+=findways(a-i,i); //ways[a-i][i]=r; } ways[a][b]=r; } return r; } int main() { int a[3],b,c,n; string s; stringstream ss; for(int

260

#include <iostream> #include <map> #include <stack> #include <queue> #include <string> #include <cstring> #define INF 1000000000 using namespace std; string row[205]; bool trace[205][205]; int N; struct node{ int x; int y; }; int floodFillDfs(node a) { //stack<node> s; queue<node> s; map<int,int> mp; s.push(a); int i,j; int r =0; while(!s.empty()) { node t= s.front();//s.top(); s.pop(); i=t.x; j=t.y;

10724

#include <iostream> #include <map> #include <cmath> #include <string> #include <vector> #include <cstring> #define INF 1000000000 #define EP 1e-6 using namespace std; struct point{ int x; int y; }; struct DD{ int i,j; double cst,edge; DD(double cst,double edge,int i,int j):cst(cst),edge(edge),i(i),j(j){ } bool operator < (const DD& d )const{ if(abs(cst-d.cst)>=EP) return cst<d.cst; if(abs(edge-d.edge)>=EP) return edge>d.edge; if(i!=d.i) return

247

#include <iostream> #include <map> #include <string> #include <cstring> #define INF 1000000000 using namespace std; int gr[30][30]; map<string,int> mp; map<int,string> np; int visit[30]; int main() { int n,m,c=0; int kase = 1; string s1,s2; while(cin>>n) { cin>>m; if(n+m==0) break; for(int i=0;i<26;i++) { for(int j=0;j<26;j++) { if(i==j) gr[i][j]=0; else { gr[i][j]=INF; } } } mp.clear(); np.clear(); int

10793

#include <iostream> #include <map> #include <vector> #define INF 1000000000 using namespace std; int L,D; int gr[105][105]; map<int,int> mp; int main() { int kase=1; int t,u,v,c; cin>>t; while(t–) { for(int i=0;i<105;i++) { for(int j=0;j<105;j++) { if(i==j) gr[i][j]=0; else gr[i][j]=INF; } } cin>>L>>D; for(int i=1;i<=D;i++) { cin>>u>>v>>c; if(gr[u][v]>c) { gr[u][v]=c; gr[v][u]=c; } } for(int k=1;k<=L;k++) { for(int

222

#include <iostream> #include <cstdio> #include <queue> #define INF 1000000 using namespace std; struct state{ int presnt; double rem_gas; double cost; }; double d[55],price_gal[55]; double gr[55][55],dst[55][55]; bool visit[55]; int L; double dist,cango; double capacity,dist_pergal,price; int station; double MN; int recurs(state a) { int pos = a.presnt; double gaso = a.rem_gas; double cst = a.cost; state t;

10075

Theory: Distance This uses the ‘haversine’ formula to calculate the great-circle distance between two points – that is, the shortest distance over the earth’s surface – giving an ‘as-the-crow-flies’ distance between the points (ignoring any hills they fly over, of course!). Haversine formula: a = sin²(Δφ/2) + cos φ1 * cos φ2 * sin²(Δλ/2) c = 2