#include<bits/stdc++.h> using namespace std; int main() { int n,k; int a[15]; a[0]=1; for(int i=1; i<15; i++) a[i]=a[i-1]*i; while(cin>>n>>k) { int result=a[n]; while(k--) { int x; cin>>x; result/=a[x]; } cout<<result<<endl; } return 0; }
Wednesday, November 16, 2016
UVa 10105
UVa 494
#include<bits/stdc++.h> using namespace std; int main() { string l,ll; while(getline(cin,l) && getline(cin,ll)) { set<string>s1,s2; string num; istringstream str1(l.c_str()); while(str1>>num) { s1.insert(num); } istringstream str2(ll.c_str()); while(str2>>num) { s2.insert(num); } set<string>:: iterator it,ix; int ab=0; for(it=s1.begin(); it !=s1.end(); it++) { ix=s2.find(*it); if(ix!=s2.end()) ab++; } int ba=0; for(it=s2.begin(); it!=s2.end(); it++) { ix=s1.find(*it); if(ix!=s1.end()) ba++; } if(ab==0 && ba==0) cout<<"A and B are disjoint"<<endl; else if(ab==ba && (ab==s1.size() && ba==s2.size())) cout << "A equals B" << endl; else if(ab==s1.size() && (s1.size()<s2.size())) cout << "A is a proper subset of B" << endl; else if(ba==s2.size() && (s2.size()<s1.size())) cout << "B is a proper subset of A" << endl; else cout << "I'm confused!" << endl; } return 0; }
UVa 694
#include<bits/stdc++.h> #define ll long long #define kase(i) printf("Case %d: ",i) using namespace std; int main() { ll a,b,c,i; int j=1; while(cin>>a>>b) { c=a; if(a<0 && b<0) break; for(i=1;;i++) { if(a==1) break; if(a%2==0) a=a/2; else a=3*a+1; if(a>b) break; } kase(j); cout<<"A = "<<c<<", Limit = "<<b<<", number of terms = "<<i<<endl; j++; } return 0; }
Tuesday, November 8, 2016
UVa 11715
#include<bits/stdc++.h> using namespace std; int main() { int T; int c = 0; double u, v, t, a, s; while (cin >> T) { if (T == 0) break; c++; cout << "Case " << c << ": "; switch (T) { case 1: cin >> u >> v >> t; a = (v - u) / t; s = u * t + 0.5 * a * t * t; cout << setprecision(3) << fixed << s << " " << a << endl; break; case 2: cin >> u >> v >> a; t = (v - u) / a; s = u * t + 0.5 * a * t * t; cout << setprecision(3) << fixed << s << " " << t << endl; break; case 3: cin >> u >> a >> s; t = (-u + sqrt(u * u + 2 * a * s)) / a; v = a * t + u; cout << setprecision(3) << fixed << v << " " << t << endl; break; case 4: cin >> v >> a >> s; t = (-v + sqrt(v * v - 2 * a * s)) / -a; u = v - a * t; cout << setprecision(3) << fixed << u << " " << t << endl; break; } } return 0; }
Wednesday, November 2, 2016
UVa 1230
import java.util.Scanner; import java.math.BigInteger; class Main { public static void main(String args[]) { Scanner sc = new Scanner(System.in); int c = sc.nextInt(); while (c-- > 0) { BigInteger x = BigInteger.valueOf(sc.nextInt()); BigInteger y = BigInteger.valueOf(sc.nextInt()); BigInteger n = BigInteger.valueOf(sc.nextInt()); System.out.println(x.modPow(y, n)); } } }
UVa 343
import java.io.*; import java.util.*; import java.math.*; class Main{ void sol() { Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in))); while(in.hasNext()) { String a=in.next(); String b=in.next(); BigInteger b1,b2; boolean f=false; for(int i=2; i<=36; i++) { try{ b1=new BigInteger(a,i); } catch(Exception e) { continue; } for(int j=2; j<=36; j++) { try{ b2= new BigInteger(b,j); } catch(Exception e) { continue; } if(b1.compareTo(b2)==0){ f=true; System.out.println(a + " (base " + i + ") = " + b + " (base " + j + ")"); break; } } if(f) break; } if(!f) System.out.println(a + " is not equal to " + b + " in any base 2..36"); } } public static void main(String args[]) { Main uva343 = new Main(); uva343.sol(); } }
UVa 10302
#include<bits/stdc++.h> #define ll long long using namespace std; int main() { ll a[50005]; a[1]=1; for(ll i=2; i<=50005; i++) { a[i]=a[i-1]+(i*i*i); } ll n; while(cin>>n) { cout<<a[n]<<endl; } return 0; }
UVa 392
#include<bits/stdc++.h> #define M 9 using namespace std; int main() { int a[M],fr,i; while(cin>>a[0]) { for(i=1;i<M;i++) cin>>a[i]; fr=8; for(i=0;i<M;i++) if(a[i]!=0) { fr=i; break; } if(fr==8) cout<<a[fr]; else { if(a[fr]==-1) cout<<"-"; else if(a[fr]==1) cout<<""; else cout<<a[fr]; cout<<"x"; if(fr!=7) cout<<"^"<<8-fr; for(i=fr+1;i<M;i++) if(a[i]!=0) { if(a[i]<0) cout<<" - "; else cout<<" + "; if((a[i]!=-1 && a[i]!=1) || i==8) { if(a[i]<0) cout<<a[i]*(-1); else cout<<a[i]; } if(i!=8) cout<<"x"; if(i!=7 && i!=8) cout<<"^"<<8-i; } } cout<<endl; } return 0; }
Subscribe to:
Posts (Atom)