「topcoder」Kodifica – Pratice Round 1
打了场莫名其妙的比赛
150
You need to update the balance in your checkbook. You know your starting balance, the total amount spent using your debit card, and the total value of checks that have been written. Return your ending balance.
a-b-c。。。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
#include<iostream> #include<cstdio> #include<cstring> #include<cstdlib> #include<algorithm> #include<cmath> #include<vector> #define pa pair<int,int> #define inf 1000000000 #define eps 1e-8 #define ll long long using namespace std; class CheckbookRegister{ public: int updateBalance(int startingBalance, int debits, int checks){ return startingBalance-debits-checks; } }; |
500
Preparing a national budget involves sums of large numbers. These numbers should be formatted in a nice way. Your task is, given some nicely formatted costs (in US dollars and cents), add up the costs and return the nicely formatted total cost. The nice format is: Numbers are decimal (base ten). Always display the cents as two digits to the right of the decimal point, even if this gives trailing zeros. Always display at least one digit to the left of the decimal point. Unless the absolute value of the number is less than one dollar, use no leading zeros. If the absolute value of the number is less than one dollar there should be one zero to the left of the decimal point. If the number of digits to the left of the decimal point is five or more, then insert commas between groups of three digits from right to left from the decimal point. (see examples) If the number is positive (greater than or equal to zero) the first character is “$”. If the number is negative (strictly less than zero) then the first two characters are “-$”.
计算一堆money的和。。。FST了TAT
改了竟然 没 地 方 交 !!!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
#include<iostream> #include<cstdio> #include<cstring> #include<cstdlib> #include<algorithm> #include<cmath> #include<vector> #define pa pair<int,int> #define inf 1000000000 #define eps 1e-8 #define ll long long using namespace std; double a[55],s1,s2; string b; void getnum(string a) { s1=0,s2=0; int f=1; for(int i=0;a[i]!='.';i++) if(a[i]=='-')f=-1; else if(a[i]!='$'&&a[i]!=',') s1=s1*10+(a[i]-'0'); for(int i=a.length()-1;a[i]!='.';i--) s2=s2/10+(a[i]-'0')*0.1; if(f==-1)s1=-s1,s2=-s2; } class NationalBudget{ public: string tally(vector <string> costs) { b=""; int n=costs.size(); ll ans=0,tmp=0; for(int i=0;i<n;i++) { getnum(costs[i]); ans+=(s1+s2)*100; tmp+=s2*100; } if(ans<0){b.push_back('-');tmp=-tmp;ans=-ans;} if(tmp<0)tmp=100+tmp; b.push_back('$'); ans/=100; ll k=1,t=1; while(k*10<=ans)k*=10; while(t*1000<=ans)t*=1000; while(k) { b.push_back(ans/k%10+'0');k/=10; if(k==t/10&&t!=1&&ans>=10000)b.push_back(','),t/=1000; } b.push_back('.'); b.push_back(tmp/10%10+'0'); b.push_back(tmp%10+'0'); return b; } }c; |
Cat Taro likes lucky strings. The digits 4 and 7 are considered lucky. A lucky string is a string such that each of its characters is a lucky digit (i.e., either ‘4’ or ‘7’). Consider some lucky string S. In one turn Taro can swap any two (not necessarily consecutive) characters of that string. He considers the string S very lucky if its characters can be sorted into non-decreasing order using at most K turns. You are given two ints N and K. Let X be the number of different very lucky strings of length N. Return the value (X modulo 1,000,000,007).
枚举放了i个4,再枚举前i个中有j个4,则交换次数为j,方案数排列组合算一算
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
#include<iostream> #include<cstdio> #include<cstring> #include<cstdlib> #include<algorithm> #include<cmath> #include<vector> #define pa pair<int,int> #define inf 1000000000 #define eps 1e-8 #define mod 1000000007 #define ll long long using namespace std; ll c[1005][1005]; void C() { c[0][0]=1; for(int i=1;i<=1000;i++) { c[i][0]=1; for(int j=1;j<=1000;j++) c[i][j]=(c[i-1][j]+c[i-1][j-1])%mod; } } class TaroLuckyStrings{ public: int getNumber(int N, int K) { ll ans=0; C(); for(int i=0;i<=N;i++) for(int j=0;j<=i;j++) { if(i-j<=K)ans=(ans+c[i][j]*c[N-i][i-j])%mod; } return ans; } }; |