633

#include <iostream> #include <cstdio> #include <cstring> #include <string> #include <queue> using namespace std; int stx,sty,edx,edy; int gr[405][405]; int dirx[8]={-2,-2,2,2,1,1,-1,-1}; int diry[8]={1,-1,1,-1,2,-2,2,-2}; int dx[4]={2,2,-2,-2}; int dy[4]={-2,2,2,-2}; int n; int bfs() { queue<int> q; int x,y; //int visit[405][405]; //memset(visit,0,sizeof(visit)); int moveTyp=0,move; int step=0,stepCount; q.push(stx);q.push(sty);q.push(moveTyp);q.push(step); if(gr[stx][sty]==1) return -1; else if(gr[edx][edy]==1) return -1; while(!q.empty()) { x = q.front();q.pop(); y

627

#include <iostream> #include <cstdio> #include <sstream> #include <vector> #include <string> #include <cstring> #include <queue> using namespace std; vector<int> vb[305]; vector<int> par; bool bfs(int path[],int st,int ed) { int visit[400]; for(int i=0;i<400;i++) visit[i]=0; queue<int> q; q.push(st); visit[st]=1; int a,b; if(st==ed) return 1; while(!q.empty()) { a = q.front();q.pop(); if(a==ed) return 1; for(int i=0;i<vb[a].size();i++) { b = vb[a][i];

599

#include <iostream> #include <cstdio> #include <cstring> #include <string> using namespace std; int parent[26]; int countNodes[26]; int getparent(int n) { if(parent[n]==n) return n; else return parent[n]=getparent(parent[n]); } void unite(int a,int b) { parent[getparent(a)]=getparent(b); } int main() { int t; string str; scanf("%d",&t); getchar(); while(t–) { str=""; for(int i=0;i<26;i++) { parent[i]=i; countNodes[i]=0; } while(getline(cin,str),str[0]!='*') { unite(str[1]-'A',str[3]-'A'); }

590

#include <iostream> #include <cstdio> #include <cstdio> #include <cstring> #include <vector> #include <cmath> #include <queue> #include <cstdlib> #define INF 1000000000 #define ll long long using namespace std; int n,k; int flight_schedule_cost[11][11][40];//flight_schedule_cost[city][tocity][dayno]=cost of that day frm ct1 to cty 2 int periodOfCity[11][11]; ll dp[1010][15];//ll dp[day][citypath]; int kase=1; int costFromTheCity(int day,int startCity,int destination_city) { int schedulePeriod = periodOfCity[startCity][destination_city];

11734

#include <cstdio> #include <vector> #include <cstring> #include <algorithm> #include <iostream> using namespace std; int main() { int t,kase=1; string org,ans,tmp1,tmp2; scanf("%d",&t); getchar(); while(t–) { getline(cin,ans); getline(cin,org); if(org.size()==ans.size()) { bool f=0; for(int i=0;i<org.size();i++) { if(org[i]!=ans[i]) { f=1;break; } } if(f) printf("Case %d: Wrong Answer\n",kase++); else printf("Case %d: Yes\n",kase++); } else { tmp1="";tmp2=""; for(int i=0;i<org.size();i++) { if(org[i]!='

11934

Have some idea about Remainder Theorem, not necessary to solve the problem but it is good to revise some theorem. #include <iostream> #include <cstdio> #include <sstream> #include <string> #define ll long long using namespace std; int main() { int a,b,c,d,L; while(scanf("%d%d%d%d%d",&a,&b,&c,&d,&L)) { if(a==0 && b==0 && c==0 && d==0 && L==0) break; if(a==0 && b==0

11936

#include <iostream> #include <cstdio> #include <sstream> #include <string> using namespace std; int main() { int n,a,b,c; scanf("%d",&n); while(n–) { scanf("%d%d%d",&a,&b,&c); bool OK=1; if(a>=(b+c)) OK=0; if(b>=(a+c)) OK=0; if(c>=(a+b)) OK=0; if(OK) printf("OK\n"); else printf("Wrong!!\n"); } return 0; }  

11610

To solve the problem indexes of the array are also needed to be updated and queried. #include <cstdio> #include <vector> #include <cstring> #include <algorithm> #include <iostream> using namespace std; struct RevPrime{ int reversePrime; int factorCount; }; int prime[1000001]; RevPrime arr[80000]; int Bit[2][80000]; vector<int> vb; int k=1; int reverse(int a) { int num=0; while(a) { num*=10;