Thursday, September 1, 2016

UVa - 490 - Rotating Sentences

Problem link:
490 - Rotating Sentences

Solution:
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long LL;
  4. const int S = 103;
  5. const int MOD = 1e9+7;
  6. const double pi = 2 * acos (0.0);
  7. int _I(){int x; scanf("%d"&x); return x;}
  8. LL _LL(){LL x; scanf("%lld"&x); return x;}
  9. int dirX[]={10-101-11-1};
  10. int dirY[]={010-11-1-11};
  11. int rX[] = {1122-1-1-2-2};
  12. int rY[] = {2-21-12-21-1};
  13.  
  14. template <class T> T Distance(T x1, T y1, T x2, T y2){return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));};
  15.  
  16. int sset(int N, int pos){return N=N|(1<<pos);}
  17. bool check(int N, int pos){return (bool)(N&(1<<pos));}
  18. int reset(int N, int pos){return N=N&~(1<<pos);}
  19. ///...............Code Starts From Here...............///
  20.  
  21. char s[S][S];
  22.  
  23. int main(){
  24.     int k = 0, mx = 0;
  25.     memset(s, ' 'sizeof(s));
  26.     while(gets(s[k])){
  27.         int sz = strlen(s[k]);
  28.         s[k][sz] = 32;
  29.         mx = max(mx, sz);
  30.         k++;
  31.     }
  32.     for(int i = 0; i < mx; i++){
  33.         for(int j = k-1; j >= 0; j--){
  34.             printf("%c", s[j][i]);
  35.         }
  36.         puts("");
  37.     }
  38.     return 0;
  39. }

UVa - 306 - Cipher

Problem link:
306 - Cipher

Solution:
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long LL;
  4. const int S = 203;
  5. const int MOD = 1e9+7;
  6. const double pi = 2 * acos (0.0);
  7. int _I(){int x; scanf("%d"&x); return x;}
  8. LL _LL(){LL x; scanf("%lld"&x); return x;}
  9. int dirX[]={10-101-11-1};
  10. int dirY[]={010-11-1-11};
  11. int rX[] = {1122-1-1-2-2};
  12. int rY[] = {2-21-12-21-1};
  13.  
  14. template <class T> T Distance(T x1, T y1, T x2, T y2){return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));};
  15.  
  16. int sset(int N, int pos){return N=N|(1<<pos);}
  17. bool check(int N, int pos){return (bool)(N&(1<<pos));}
  18. int reset(int N, int pos){return N=N&~(1<<pos);}
  19. ///...............Code Starts From Here...............///
  20.  
  21. char ans[S];
  22. char input[S];
  23. int number[S];
  24.  
  25. int main(){
  26.     int n;
  27.     while(scanf("%d"&n) == 1 && n){
  28.         for(int i = 0; i < n; i++)number[i] = _I()-1;
  29.         int k;
  30.         while(scanf("%d"&k) == 1 && k){
  31.             getchar();
  32.             gets(input);
  33.             memset(ans, ' 'sizeof(ans));
  34.             int ind, cn;
  35.             for(int i = 0; input[i]; i++){
  36.                 ind = i, cn = 0;
  37.                 int f = 0;
  38.                 while(cn < k){
  39.                     if(ind == i && f){
  40.                         f = 2;
  41.                         break;
  42.                     }
  43.                     ind = number[ind];
  44.                     cn++, f = 1;
  45.                 }
  46.                 int p = k%cn;
  47.                 if(== 2){
  48.                     ind = i, cn = 0;
  49.                     while(cn < p){
  50.                         ind = number[ind];
  51.                         cn++;
  52.                     }
  53.                 }
  54.                 ans[ind] = input[i];
  55.             }
  56.             for(int i = 0; i < n; i++)printf("%c", ans[i]);
  57.             puts("");
  58.         }
  59.         puts("");
  60.     }
  61.     return 0;
  62. }

UVa - 11044 - Searching for Nessy

Problem link:
11044 - Searching for Nessy

Solution:
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long LL;
  4. const int S = 300003;
  5. const int MOD = 1e9+7;
  6. const double pi = 2 * acos (0.0);
  7. int _I(){int x; scanf("%d"&x); return x;}
  8. LL _LL(){LL x; scanf("%lld"&x); return x;}
  9. int dirX[]={10-101-11-1};
  10. int dirY[]={010-11-1-11};
  11. int rX[] = {1122-1-1-2-2};
  12. int rY[] = {2-21-12-21-1};
  13.  
  14. template <class T> T Distance(T x1, T y1, T x2, T y2){return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));};
  15.  
  16. int sset(int N, int pos){return N=N|(1<<pos);}
  17. bool check(int N, int pos){return (bool)(N&(1<<pos));}
  18. int reset(int N, int pos){return N=N&~(1<<pos);}
  19. ///...............Code Starts From Here...............///
  20.  
  21. int main(){
  22.     int t = _I();
  23.     while(t--){
  24.         int n = _I(), m = _I();
  25.         n /= 3;
  26.         m /= 3;
  27.         n *= m;
  28.         printf("%d\n", n);
  29.     }
  30.     return 0;
  31. }