#include<bits/stdc++.h> using namespace std; int DP[10000001] = {0}; int main() { int t, n, i; double last = 0; for(i = 1; i <= 10000000; i++) { last += log10(i); DP[i] = (int)last; } scanf("%d", &t); while(t--) { scanf("%d", &n); printf("%d\n",DP[n]+1); } return 0; }
Thursday, June 23, 2016
UVA 1185
UVA 12503
#include<iostream> using namespace std; #define debug(x) cout<<">"<<x<<endl; int main() { int t,p1,p2; string s; int n,i; string pos[101]; while(cin>>t) { while(t--) { int tot=0; cin>>n; for(i=0; i<n; i++) { cin>>s; if(s=="LEFT") { tot-=1; pos[i]=s; } else if(s=="RIGHT") { tot+=1; pos[i]=s; } else{ cin>>s; cin>>p2; if(pos[p2-1]=="LEFT") { tot-=1; pos[i]=pos[p2-1]; } else if(pos[p2-1]=="RIGHT") { tot+=1; pos[i]=pos[p2-1]; } } } cout<<tot<<endl; } } return 0; }
Subscribe to:
Posts (Atom)