Advertisement
PikMike

Untitled

Oct 25th, 2016
390
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.65 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. #define pb push_back
  4. #define mp make_pair
  5. #define sz(x) (int)(x).size()
  6. #define ll long long
  7. #define ld long double
  8. #define ft first
  9. #define sc second
  10. #define pii pair<int, int>
  11. #define pll pair<ll, ll>
  12. #define forn(i, t) for(int i = 0; i < (t); i++)
  13. #define fore(i, f, t) for(int i = (f); i < (t); i++)
  14. #define forr(i, f, t) for(int i = (f) - 1; i >= (t); i--)
  15. #define all(x) (x).begin(), (x).end()
  16. #define ins insert
  17.  
  18. const int INF = 2147483647;
  19. const int MOD = 1000000007;
  20. const ll INF64 = 9223372036854775807;
  21. const ld EPS = 1e-7;
  22.  
  23. using namespace std;
  24.  
  25.  
  26. void encode(string s){
  27.     int n = sz(s);
  28.     int m = 0;
  29.     while ((1 << m) < m + n + 1)
  30.         m++;
  31.     forn(i, m)
  32.         s.insert((1 << i) - 1, "0");
  33.     n = sz(s);
  34.     forn(i, m){
  35.         int cur = 0;
  36.         forn(j, n)
  37.             if (((j + 1) & (1 << i)) != 0)
  38.                 cur ^= (s[j] == '1');
  39.         s[(1 << i) - 1] = ('0' + cur);
  40.     }
  41.     cout << s << "\n";
  42. }
  43.  
  44.  
  45. void decode(string s){
  46.     int ans = 0, n = sz(s);
  47.     int m = 0;
  48.     while ((1 << m) < n)
  49.         m++;
  50.     forn(i, m){
  51.         int cur = (s[(1 << i) - 1] == '1');
  52.         forn(j, n)
  53.             if (((j + 1) & (1 << i)) != 0)
  54.                 cur ^= (s[j] == '1');
  55.         if (s[(1 << i) - 1] != ('0' + cur))
  56.             ans ^= (1 << i);
  57.     }
  58.     if (ans != 0)
  59.         s[ans - 1] = (s[ans - 1] == '0' ? '1' : '0');
  60.     string t = "";
  61.     forn(i, n)
  62.         if (__builtin_popcount(i + 1) > 1)
  63.             t += s[i];
  64.     cout << ans << " " << t << "\n";
  65. }
  66.  
  67.  
  68. int main(){
  69.     string s = "0000000000000";
  70.     // encode(s);
  71.     // decode(s);
  72.     return 0;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement