- /****************##### بِسْمِ اللَّهِ الرَّحْمَنِ الرَّحِيم #####*******************
- __________________________________________________________________________
- ###################### Ya-Seen Arafat(ACWizard) #########################
- ###################### UAP-CSE-33B #########################
- *************************************************************************/
- #include <bits/stdc++.h>
- #define sc(n) scanf("%d", &n)
- #define S 30003
- using namespace std;
- typedef long long LL;
- LL N, dp[15][S];
- LL coins[] = {5, 10, 20, 50, 100, 200, 500, 1000, 2000, 5000, 10000};
- LL Dollars(int ind, LL tot){
- if(tot == 0LL)return 1LL;
- if(tot < 0)return 0LL;
- if(ind >= 11)return 0LL;
- if(dp[ind][tot] != -1LL)return dp[ind][tot];
- dp[ind][tot] = (Dollars(ind, tot-coins[ind])+Dollars(ind+1, tot));
- return dp[ind][tot];
- }
- void Do(){
- char n[10];
- memset(dp, -1LL, sizeof(dp));
- while(scanf("%s", n) == 1){
- N = 0LL;
- for(int i = 0; n[i]; i++){
- if(n[i] >= '0' && n[i] <= '9')
- N = (N*10LL)+(n[i]-'0');
- }
- if(N == 0LL)break;
- printf("%6s%17lld\n", n, Dollars(0, N));
- }
- }
- int main(){
- ios_base::sync_with_stdio(0); cin.tie(0);
- #ifndef ONLINE_JUDGE
- ///freopen("inp","r",stdout);
- ///freopen("contest.txt","w",stdout);
- #endif
- Do();
- return 0;
- }
Sunday, June 14, 2015
UVa - 147 - Dollars
UVa - 11517 - Exact Change
- /****************##### بِسْمِ اللَّهِ الرَّحْمَنِ الرَّحِيم #####*******************
- __________________________________________________________________________
- ###################### Ya-Seen Arafat(ACWizard) #########################
- ###################### UAP-CSE-33B #########################
- *************************************************************************/
- #include <bits/stdc++.h>
- #define sc(n) scanf("%d", &n)
- #define S 103
- using namespace std;
- typedef long long LL;
- int p, n, mn, ans;
- int arr[S], dp[S][S*100];
- int Exchange(int ind, int tot, int coin){
- if(tot >= p)return tot;
- if(ind >= n)return INT_MAX;
- if(dp[ind][tot] != -1)return dp[ind][tot];
- dp[ind][tot] = 0;
- dp[ind][tot] += Exchange(ind+1, tot+arr[ind], coin+1);
- mn = min(mn, dp[ind][tot]);
- Exchange(ind+1, tot, coin);
- return mn;
- }
- int Coins(int ind, int coin, int tot){
- if(tot == ans)return coin;
- if(tot > ans)return INT_MAX;
- if(ind >= n)return INT_MAX;
- if(dp[ind][tot] != -1)return dp[ind][tot];
- dp[ind][tot] = 0;
- dp[ind][tot] += Coins(ind+1, coin+1, tot+arr[ind]);
- mn = min(mn, dp[ind][tot]);
- Coins(ind+1, coin, tot);
- return mn;
- }
- void Do(){
- int t;
- sc(t);
- while(t--){
- sc(p);
- sc(n);
- memset(dp, -1, sizeof(dp));
- for(int i = 0; i < n; i++)sc(arr[i]);
- sort(arr, arr+n);
- reverse(arr, arr+n);
- mn = INT_MAX;
- ans = Exchange(0, 0, 0);
- cout << ans << " ";
- memset(dp, -1, sizeof(dp));
- mn = INT_MAX;
- cout << Coins(0, 0, 0) << endl;
- }
- }
- int main(){
- ios_base::sync_with_stdio(0); cin.tie(0);
- #ifndef ONLINE_JUDGE
- ///freopen("inp","r",stdout);
- ///freopen("contest.txt","w",stdout);
- #endif
- Do();
- return 0;
- }
Saturday, June 13, 2015
UVa - 386 - Perfect Cubes
- /****************##### بِسْمِ اللَّهِ الرَّحْمَنِ الرَّحِيم #####*******************
- __________________________________________________________________________
- ###################### Ya-Seen Arafat(ACWizard) #########################
- ###################### UAP-CSE-33B #########################
- *************************************************************************/
- #include <bits/stdc++.h>
- #define sc(n) scanf("%d", &n)
- #define S 10000003
- using namespace std;
- typedef long long LL;
- struct data{
- int Num;
- vector <int> Qube;
- }arr[S];
- int qube[S];
- int cmp(data p, data q){
- if(p.Num == q.Num)return p.Qube < q.Qube;
- return p.Num < q.Num;
- }
- void asgn_qube(){
- for(int i = 2; i <= 200; i++)qube[i*i*i] = i;
- }
- int prfct_qube(int z){
- int w, x, y;
- for(int i = 2; i <= 200; i++){
- w = i*i*i;
- for(int j = i+1; j <= 200; j++){
- x = j*j*j;
- for(int k = j+1; k <= 200; k++){
- y = k*k*k;
- if(w+x+y < S && qube[w+x+y]){
- arr[z].Num = qube[w+x+y];
- arr[z].Qube.push_back(i);
- arr[z].Qube.push_back(j);
- arr[z].Qube.push_back(k);
- z++;
- }
- }
- }
- }
- sort(arr, arr+z, cmp);
- return z;
- }
- void Do(){
- asgn_qube();
- int lim = prfct_qube(0);
- int l = 0;
- for(int i = 0; i < lim; i++){
- int sz = arr[i].Qube.size();
- cout << "Cube = " << arr[i].Num << ", ";
- for(int j = 0; j < 3; j++){
- if(!j)cout << "Triple = (";
- if(j == 2)cout << arr[i].Qube[j] << ")" << endl;
- else cout << arr[i].Qube[j] << ",";
- }
- }
- }
- int main(){
- ios_base::sync_with_stdio(0); cin.tie(0);
- #ifndef ONLINE_JUDGE
- ///freopen("inp","r",stdout);
- ///freopen("contest.txt","w",stdout);
- #endif
- Do();
- return 0;
- }
Sunday, June 7, 2015
UVa - 729 - The Hamming Distance Problem
- #include <bits/stdc++.h>
- using namespace std;
- vector <int> Ham;
- int n;
- int main(){
- int t, p, f = 0, bl = 0;
- scanf("%d", &t);
- while(t--){
- scanf("%d %d", &n, &p);
- int b = n-p;
- while(p--)Ham.push_back(1);
- while(b--)Ham.push_back(0);
- reverse(Ham.begin(), Ham.end());
- if(bl)puts(""); bl = 1;
- for(int i = 0; i < n; i++)cout << Ham[i];
- puts("");
- while(next_permutation(Ham.begin(), Ham.end())){
- for(int i = 0; i < n; i++)cout << Ham[i];
- puts("");
- }
- Ham.clear();
- }
- return 0;
- }
Saturday, June 6, 2015
LightOJ - 1225 - Palindromic Numbers (II)
- #include <bits/stdc++.h>
- using namespace std;
- int main(){
- int t, cs = 0, f;
- char n[13], p[13];
- scanf("%d", &t);
- while(t--){
- scanf("%s", n);
- int sz = strlen(n);
- strcpy(p, n);
- reverse(n, n+sz);
- printf("Case %d: ", ++cs);
- puts((strcmp(n, p) == 0)?"Yes":"No");
- }
- return 0;
- }
LightOJ - 1182 - Parity
- #include <bits/stdc++.h>
- using namespace std;
- int main(){
- int t, n, cs = 0;
- cin >> t;
- while(t--){
- int m = 0;
- cin >> n;
- while(n){
- if(n%2)m++;
- n /= 2;
- }
- cout << "Case " << ++cs << ": ";
- puts((m%2)?"odd":"even");
- }
- return 0;
- }
Subscribe to:
Posts (Atom)