#include <iostream> #include <math.h> #include <map> #include <stdio.h> #include <string> #include <vector> using namespace std; map<int,int> mp; int fib[50]; double dp[1010]; int main() { fib[0]=0; fib[1]=1; fib[2]=2; mp[1]=1; mp[2]=2; for(int i=3;i<=20;i++) { fib[i]=fib[i-1]+fib[i-2]; mp[fib[i]]=i; } dp[1]=.4; for(int i=1;i<=1000;i++) { double p=i*1.6; double d=1000000; for(int j=1;j<=18;j++) { if(i-fib[j]>=0) { int a=mp[fib[j]]; double x; if((fib[a+1]+dp[i-fib[j]]-p)<0) { x=-1*(fib[a+1]+dp[i-fib[j]]-p);
Month: June 2014
903
#include <iostream> using namespace std; int main() { int n; int Break=0; long long int res,res1,res2,res3,res4,rank,diff; long long int b_left,b_ryt,t_left,t_ryt; while(cin>>n) { res=1; res1=1; res2=1; res3=1; res4=1; Break=0; if(n==1) { cout<<7<<";"<<8<<";"<<9<<";\n"; cout<<6<<";"<<1<<";"<<2<<";\n"; cout<<5<<";"<<4<<";"<<3<<";\n"; continue; } for(long long int i=0;i<1500000000;i++) { if(Break) break; res1+=i*2; if(res1>=n) { rank=i; res=res1; Break=1; //continue; } res2+=i*4; if(res2>=n) { rank=i; res=res2;
993
Solution: #include <iostream> #include <vector> using namespace std; int main() { int t,c; long long int n; vector<long long int> v; cin>>t; while(t–) { cin>>n; if(n<=9) { cout<<n<<"\n"; continue; } while(n>=10) { v.clear(); c=0; for(long long int i=9;i>=2;i–) { if(n%i==0) { c=1; n/=i; v.push_back(i); break; } } if(n<10) { v.push_back(n); break; } if(c==0) { v.clear();
991
Theory: For larger n, imagine choosing an arbitrary pair of people to shake hands. You’ve now divided the circle into two smaller circles (one of which may have 0 people in it). The number of ways you can arrange the rest of the people is the product of the answers for the two smaller circles.
960
Gaussian Prime Integer Problem Theory: First we should know that the multiple of two lengths is the length of the original one. For example, (4,3) has a length of 5, so if we can break (4,3) down into A & B, length(A) * length(B) is also 5. Next we’ll iterate through all possible combinations (lengths.)