/**********12502**********/ #include <iostream> #include <string.h> #include <stdio.h> #include <math.h> #define lld long long using namespace std; int main() { int t;//a= 2/15 b=1/12 double x,y,z; double extra,avg; cin>>t; while(t–) { cin>>x>>y>>z; avg=(x+y)/3; extra = x-avg; printf("%.0lf\n",(extra*z)/avg); } return 0; }
Year: 2014
12345
#include <iostream> #include <string.h> #include <map> using namespace std; bool trace[1000005]; int a[50005]; int main() { int n,q,res; char c; int idx,val; cin>>n>>q; for(int i=0;i<n;i++) { cin>>a[i]; } while(q–) { cin>>c>>idx>>val; if(c=='M') { a[idx]=val; } else if(c=='Q') { res=0; for(int i=idx;i<val;i++) { if(trace[a[i]]==0) res++; trace[a[i]]=1; } for(int i=idx;i<val;i++) trace[a[i]]=0; cout<<res<<"\n"; } } }
12554
#include <iostream> #include <string> using namespace std; string str[105]; string song[16]={"Happy", "birthday", "to", "you", "Happy", "birthday", "to", "you", "Happy", "birthday", "to", "Rujia", "Happy", "birthday", "to", "you",}; int main() { int n; int i=0; cin>>n; int org = n; while(n–) { cin>>str[i++]; } n=org; if(org<=16) { for(int j=0;j<16;j++) { cout<<str[j%i]<<": "; cout<<song[j]<<"\n"; } } else {
12527
#include <stdio.h> #include <iostream> #include <math.h> #include <string.h> #include <time.h> using namespace std; int trace[5001]; int main() { //clock_t t1,t2; //t1=clock(); int cnt=0; int arr[10]; for(int i=1;i<=5000;i++) { int tmp=i; trace[i]=cnt; memset(arr,0,sizeof(arr)); while(tmp) { arr[tmp%10]++; if(arr[tmp%10]>1) { cnt++; trace[i]=cnt; break; } tmp/=10; } } int n,m; while(cin>>n>>m) { cout<<(m-n+1)-(trace[m] – trace[n-1])<<"\n"; } //cout<<cnt<<"\n"; /* t2=clock();
12517
Theory: from 0 to 99 there are 2*10^1=20 for each 0 to 9 digits. from 0 to 999 there are 3*10^2=300 for each 0 to 9 digits. so the foemulae is for 0 to n number of 9’s n*10^(n-1) for each 0 to 9 digits. And so, for upto 445 we can find total number
12532
/*****Binary Index tree 12532******/ #include <stdio.h> #include <iostream> #include <string> #include <string.h> #include <math.h> #define SZ 100005 #define ll long long using namespace std; int num[SZ]; int neg[SZ]; int zero[SZ]; int maxInd; void update(int *arr,int ind,int val) { while(ind<maxInd) { arr[ind]+=val; ind+=(ind & (-ind)); } } int read(int *arr,int ind) { int res =0; while(ind>0)
12541
#include <iostream> #include <sstream> #include <stdio.h> #include <string> #include <math.h> using namespace std; int main() { int n; double max_,min_; double day,month,yr; string s,name,young,old; stringstream ss; bool f=false; cin>>n; //getchar(); while(n–) { cin>>name>>day>>month>>yr; yr+=((month/12)+(day/365)); if(!f) { max_=yr; young = name; min_=yr; old = name; f=1; } else { if(yr>max_) { max_=yr; young = name; }
12543
#include <iostream> #include <string> #include <math.h> using namespace std; int main() { string s,maxStr,a; int max_=0; int len=0; maxStr=""; while(cin>>s) { if(s=="E-N-D") break; len=0; a=""; for(int i=0;i<s.size();i++) { if((s[i]>='a' && s[i]<='z') || (s[i]>='A' && s[i]<='Z') || s[i]=='-') { len++; if(s[i]>='A' && s[i]<='Z') a.append(1u,s[i]+32); else a.append(1u,s[i]); } } if(len>max_) { max_=len; maxStr=a; } } cout<<maxStr<<"\n"; return
10780
#include <iostream> #include <cstring> #include <math.h> #include <stdio.h> #include <vector> #include <fstream> #define ull unsigned long long using namespace std; int factor[10001][1230]; int factorcount[10001][1230]; int prime[10001]; vector<int> v; ull _MAX; void primegenerator() { double p=sqrt(10001); v.push_back(2); for(int i=3;i<p;i+=2) { if(prime[i]==0) for(int j=i*i;j<10001;j+=i) prime[j]=1; } for(int i=3;i<10001;i+=2) { if(prime[i]==0) v.push_back(i); } } void factorize() { for(int
10308
This is the problem to find the tree diameter. #include <iostream> #include <fstream> #include <sstream> #include <map> #include <vector> #include <string> #include <queue> #include <string.h> #include <stdio.h> #define ull unsigned long long #define SZ 10002 #define FOR(i,a) for(int i=0;i<a;i++) using namespace std; vector<int> graph[SZ]; bool visit[SZ]; int distnce[SZ][SZ]; ull distnode[SZ]; ull max_dist=0; int farthestnode; void