codeforces educational round 72 ABC

A. Creating a Character

Description

给出三个整数值,$str,int,exp$。

可以将exp的值分给str或者int,exp必须分配完。

求满足$str+x>int+exp-x$的方案数。

Solution

解不等式。

$$str+x>int+exp-x$$

$$2x>int+exp-str$$

$$2x \ge \lceil int+exp-str+1 \rceil$$

$$x \ge int+exp+str+2>>1$$

加上边界判断,$res=max(k+1-max(0,exp+int-str+2>>1),0)$

  1 #include <algorithm>
  2 #include <cctype>
  3 #include <cmath>
  4 #include <cstdio>
  5 #include <cstdlib>
  6 #include <cstring>
  7 #include <iostream>
  8 #include <map>
  9 #include <numeric>
 10 #include <queue>
 11 #include <set>
 12 #include <stack>
 13 #if __cplusplus >= 201103L
 14 #include <unordered_map>
 15 #include <unordered_set>
 16 #endif
 17 #include <vector>
 18 #define lson rt << 1, l, mid
 19 #define rson rt << 1 | 1, mid + 1, r
 20 #define LONG_LONG_MAX 9223372036854775807LL
 21 #define pblank putchar(' ')
 22 #define ll LL
 23 #define fastIO ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
 24 using namespace std;
 25 typedef long long ll;
 26 typedef long double ld;
 27 typedef unsigned long long ull;
 28 typedef pair<int, int> P;
 29 int n, m, k;
 30 const int maxn = 1e5 + 10;
 31 template <class T>
 32 inline T read()
 33 {
 34     int f = 1;
 35     T ret = 0;
 36     char ch = getchar();
 37     while (!isdigit(ch))
 38     {
 39         if (ch == '-')
 40             f = -1;
 41         ch = getchar();
 42     }
 43     while (isdigit(ch))
 44     {
 45         ret = (ret << 1) + (ret << 3) + ch - '0';
 46         ch = getchar();
 47     }
 48     ret *= f;
 49     return ret;
 50 }
 51 template <class T>
 52 inline void write(T n)
 53 {
 54     if (n < 0)
 55     {
 56         putchar('-');
 57         n = -n;
 58     }
 59     if (n >= 10)
 60     {
 61         write(n / 10);
 62     }
 63     putchar(n % 10 + '0');
 64 }
 65 template <class T>
 66 inline void writeln(const T &n)
 67 {
 68     write(n);
 69     puts("");
 70 }
 71 template <typename T>
 72 void _write(const T &t)
 73 {
 74     write(t);
 75 }
 76 template <typename T, typename... Args>
 77 void _write(const T &t, Args... args)
 78 {
 79     write(t), pblank;
 80     _write(args...);
 81 }
 82 template <typename T, typename... Args>
 83 inline void write_line(const T &t, const Args &... data)
 84 {
 85     _write(t, data...);
 86 }
 87 int main(int argc, char const *argv[])
 88 {
 89 #ifndef ONLINE_JUDGE
 90     freopen("in.txt", "r", stdin);
 91     // freopen("out.txt", "w", stdout);
 92 #endif
 93     int t = read<int>();
 94     while (t--)
 95     {
 96         int str = read<int>(), exp = read<int>(), k = read<int>();
 97         int res = 0;
 98         int cur = max(0, exp + k - str + 2 >> 1);
 99         res = max(k + 1 - cur, 0);
100         writeln(res);
101     }
102     return 0;
103 }
View Code

 

B. Zmei Gorynich

Description

一只怪兽有h点血

n个技能,每种技能有一个atk值和一个heal值。

atk代表当前能攻击怪兽多少血量,heal值代表此次攻击后如果怪兽血量大于0,怪兽会恢复heal血量。

技能随便扔,求最少的扔技能次数可以打败怪兽。

Solution

求出最大的atk-heal和atk。

每次只用这两者其一攻击怪兽。

贪心。

  1 #include <algorithm>
  2 #include <cctype>
  3 #include <cmath>
  4 #include <cstdio>
  5 #include <cstdlib>
  6 #include <cstring>
  7 #include <iostream>
  8 #include <map>
  9 #include <numeric>
 10 #include <queue>
 11 #include <set>
 12 #include <stack>
 13 #if __cplusplus >= 201103L
 14 #include <unordered_map>
 15 #include <unordered_set>
 16 #endif
 17 #include <vector>
 18 #define lson rt << 1, l, mid
 19 #define rson rt << 1 | 1, mid + 1, r
 20 #define LONG_LONG_MAX 9223372036854775807LL
 21 #define pblank putchar(' ')
 22 #define ll LL
 23 #define fastIO ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
 24 using namespace std;
 25 typedef long long ll;
 26 typedef long double ld;
 27 typedef unsigned long long ull;
 28 typedef pair<int, int> P;
 29 int n, m, k;
 30 const int maxn = 1e5 + 10;
 31 template <class T>
 32 inline T read()
 33 {
 34     int f = 1;
 35     T ret = 0;
 36     char ch = getchar();
 37     while (!isdigit(ch))
 38     {
 39         if (ch == '-')
 40             f = -1;
 41         ch = getchar();
 42     }
 43     while (isdigit(ch))
 44     {
 45         ret = (ret << 1) + (ret << 3) + ch - '0';
 46         ch = getchar();
 47     }
 48     ret *= f;
 49     return ret;
 50 }
 51 template <class T>
 52 inline void write(T n)
 53 {
 54     if (n < 0)
 55     {
 56         putchar('-');
 57         n = -n;
 58     }
 59     if (n >= 10)
 60     {
 61         write(n / 10);
 62     }
 63     putchar(n % 10 + '0');
 64 }
 65 template <class T>
 66 inline void writeln(const T &n)
 67 {
 68     write(n);
 69     puts("");
 70 }
 71 template <typename T>
 72 void _write(const T &t)
 73 {
 74     write(t);
 75 }
 76 template <typename T, typename... Args>
 77 void _write(const T &t, Args... args)
 78 {
 79     write(t), pblank;
 80     _write(args...);
 81 }
 82 template <typename T, typename... Args>
 83 inline void write_line(const T &t, const Args &... data)
 84 {
 85     _write(t, data...);
 86 }
 87 int main(int argc, char const *argv[])
 88 {
 89 #ifndef ONLINE_JUDGE
 90     freopen("in.txt", "r", stdin);
 91     // freopen("out.txt", "w", stdout);
 92 #endif
 93     int t = read<int>();
 94     while (t--)
 95     {
 96         n = read<int>();
 97         int h = read<int>();
 98         int MX1 = 0, MX2 = 0;
 99         for (int i = 0; i < n; i++)
100         {
101             int x = read<int>(), y = read<int>();
102             MX1 = max(MX1, x - y);
103             MX2 = max(MX2, x);
104         }
105         int res = -1;
106         if (MX2 >= h)
107             res = 1;
108         else if (MX1)
109         {
110             int p = h - MX2;
111             if (p <= 0)
112                 res = 1;
113             else
114             {
115                 res = p / MX1 + 1;
116                 if (p % MX1)
117                     ++res;
118             }
119         }
120         writeln(res == 0 ? -1 : res);
121     }
122     return 0;
123 }
View Code

 

C. The Number Of Good Substrings

Description

给出一串01字符串序列s。

求$f(s[l..r])=r-l+1,f(str)=int(str,2)$

Solution

首先只有字符1才会对答案有贡献。

对于给定的字符串,先预处理出每一个字符1的前一个1字符。

从后往前遍历,对每一个位置进行模拟到前一个1字符位置(也没有真实模拟到前一个1位置,应该说模拟到当前字符的前18位)。

每次询问,如果i-pre[i]>=cur,cur表示子串当前十进制值,那么在$pre[i]~i$一定有一个位置k满足$f(s[k,i])=cur$,记录答案。

  1 #include <algorithm>
  2 #include <cctype>
  3 #include <cmath>
  4 #include <cstdio>
  5 #include <cstdlib>
  6 #include <cstring>
  7 #include <iostream>
  8 #include <map>
  9 #include <numeric>
 10 #include <queue>
 11 #include <set>
 12 #include <stack>
 13 #if __cplusplus >= 201103L
 14 #include <unordered_map>
 15 #include <unordered_set>
 16 #endif
 17 #include <vector>
 18 #define lson rt << 1, l, mid
 19 #define rson rt << 1 | 1, mid + 1, r
 20 #define LONG_LONG_MAX 9223372036854775807LL
 21 #define pblank putchar(' ')
 22 #define ll LL
 23 #define fastIO ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
 24 using namespace std;
 25 typedef long long ll;
 26 typedef long double ld;
 27 typedef unsigned long long ull;
 28 typedef pair<int, int> P;
 29 int n, m, k;
 30 const int maxn = 2e5 + 10;
 31 template <class T>
 32 inline T read()
 33 {
 34     int f = 1;
 35     T ret = 0;
 36     char ch = getchar();
 37     while (!isdigit(ch))
 38     {
 39         if (ch == '-')
 40             f = -1;
 41         ch = getchar();
 42     }
 43     while (isdigit(ch))
 44     {
 45         ret = (ret << 1) + (ret << 3) + ch - '0';
 46         ch = getchar();
 47     }
 48     ret *= f;
 49     return ret;
 50 }
 51 template <class T>
 52 inline void write(T n)
 53 {
 54     if (n < 0)
 55     {
 56         putchar('-');
 57         n = -n;
 58     }
 59     if (n >= 10)
 60     {
 61         write(n / 10);
 62     }
 63     putchar(n % 10 + '0');
 64 }
 65 template <class T>
 66 inline void writeln(const T &n)
 67 {
 68     write(n);
 69     puts("");
 70 }
 71 template <typename T>
 72 void _write(const T &t)
 73 {
 74     write(t);
 75 }
 76 template <typename T, typename... Args>
 77 void _write(const T &t, Args... args)
 78 {
 79     write(t), pblank;
 80     _write(args...);
 81 }
 82 template <typename T, typename... Args>
 83 inline void write_line(const T &t, const Args &... data)
 84 {
 85     _write(t, data...);
 86 }
 87 char s[maxn];
 88 const int bound = 18;
 89 int pre[maxn];
 90 int main(int argc, char const *argv[])
 91 {
 92 #ifndef ONLINE_JUDGE
 93     freopen("in.txt", "r", stdin);
 94     // freopen("out.txt", "w", stdout);
 95 #endif
 96     int t;
 97     fastIO;
 98     cin >> t;
 99     while (t--)
100     {
101         cin >> s;
102         n = strlen(s);
103         ll res = 0;
104         int p = -1;
105         for (int i = 0; i < n; i++)
106             if (s[i] == '1')
107             {
108                 pre[i] = p;
109                 p = i;
110             }
111             else
112                 pre[i] = p;
113         for (int i = n - 1; i >= 0; i--)
114         {
115             int cur = 0;
116             for (int j = i; j >= i - bound && j != -1; j = pre[j])
117             {
118                 if (s[j] == '0')
119                     continue;
120                 cur += 1 << (i - j);
121                 if (i - pre[j] >= cur)
122                     ++res;
123             }
124         }
125         writeln(res);
126     }
127     return 0;
128 }
View Code

 

 

 

posted @ 2019-11-12 15:16  mool  阅读(152)  评论(0编辑  收藏  举报