ABC196 A~E

  • [A - Difference Max](https://atcoder.jp/contests/abc196/tasks/abc196_a)
    • 题目大意
    • 输入格式
    • 输出格式
    • 样例
    • 分析
    • 代码
  • [B - Round Down](https://atcoder.jp/contests/abc196/tasks/abc196_b)
    • 题目大意
    • 输入格式
    • 输出格式
    • 样例
    • 分析
    • 代码
  • [C - Doubled](https://atcoder.jp/contests/abc196/tasks/abc196_c)
    • 题目大意
    • 输入格式
    • 输出格式
    • 样例
    • 分析
    • 代码
  • [D - Hanjo](https://atcoder.jp/contests/abc196/tasks/abc196_d)
    • 题目大意
    • 输入格式
    • 输出格式
    • 样例
    • 分析
    • 代码
  • [E - Filters](https://atcoder.jp/contests/abc196/tasks/abc196_e)
    • 题目大意
    • 输入格式
    • 输出格式
    • 样例
      • 样例输入
      • 样例输出
    • 分析
    • 代码

A - Difference Max

题目大意

给定四个整数a,b,ca,b,ca,b,c和ddd。
我们要选择两个整数xxx和yyy(a≤x≤ba\le x\le ba≤x≤b;c≤y≤dc\le y\le dc≤y≤d)。输出最大的x−yx-yx−y。

−100≤a≤b≤100-100\le a\le b\le 100−100≤a≤b≤100
−100≤c≤d≤100-100\le c\le d\le 100−100≤c≤d≤100

输入格式

aba~~ba  b
cdc~~dc  d

输出格式

输出最大的x−yx-yx−y。

样例

aaa bbb ccc ddd 输出
000 101010 000 101010 101010
−100-100−100 −100-100−100 100100100 100100100 200200200
−100-100−100 100100100 −100-100−100 100100100 200200200

分析

如果要x−yx-yx−y最大,那么xxx要尽可能大、yyy要尽可能小。因此,xxx取最大值bbb,yyy取最小值ccc。所以,我们直接输出b−cb-cb−c即可。

代码

#include <cstdio>
using namespace std;int main()
{int a, b, c, d;scanf("%d%d%d%d", &a, &b, &c, &d);printf("%d\n", b - c);return 0;
}

B - Round Down

题目大意

给定一个数XXX,求⌊X⌋\lfloor X\rfloor⌊X⌋。

0≤X≤101000\le X\le 10^{100}0≤X≤10100

输入格式

XXX

输出格式

输出⌊X⌋\lfloor X\rfloor⌊X⌋。

样例

XXX 输出
5.905.905.90 555
000 000
84939825309432908832902189.909230940980909132984939825309432908832902189.909230940980909132984939825309432908832902189.9092309409809091329 849398253094329088329021898493982530943290883290218984939825309432908832902189

分析

只需找到小数点并将其及后面的数位删去再输出即可。例如:5.905\sout{.90}5.90

代码

#include <cstdio>
using namespace std;int main()
{char c;while((c = getchar()) != '\n'){if(c == '.') return 0;putchar(c);}return 0;
}

C - Doubled

题目大意

111~NNN之间有多少个数是另一个正整数重复两遍得来的?

1≤N<10121\le N<10^{12}1≤N<1012

输入格式

NNN

输出格式

输出答案。

样例

NNN 输出
333333 333
133313331333 131313
100000001000000010000000 999999999

分析

这道题说白了就是要找到最大的XXX,使得XXX重复两遍不超过NNN,并输出XXX。我们可以使用二分法求出最大的XXX。
注意:这里的二分右边界最好设置为N\sqrt NN​,否则一不小心就会溢出!

代码

#include <cstdio>
#include <cmath>
using namespace std;typedef long long LL;inline bool check(const LL& x, const LL& n)
{LL p = 1LL;while(p <= x) p *= 10LL;return x * p + x <= n;
}int main()
{LL n;scanf("%lld", &n);LL l = 0LL, r = sqrt(n);while(l < r){LL mid = l + r + 1LL >> 1LL;if(check(mid, n)) l = mid;else r = mid - 1;}printf("%lld\n", l);return 0;
}

D - Hanjo

题目大意

有一个H×WH\times WH×W的地板,请你在地板上铺砖。
有两种地砖:aaa和bbb。aaa地砖有AAA个,是2×12\times12×1的可旋转长方形。bbb地砖有BBB个,是1×11\times11×1的正方形。问要将这个地板正好铺满,总共有多少种铺法?

1≤H,W,HW≤161\le H,W,HW\le 161≤H,W,HW≤16
0≤A,B0\le A,B0≤A,B
2A+B=HW2A+B=HW2A+B=HW

输入格式

HWABH~W~A~BH W A B

输出格式

输出答案。

样例

HHH WWW AAA BBB 输出
222 222 111 222 444
333 333 444 111 181818
444 444 888 000 363636

分析

由于数据范围较小,我们可以用暴力搜索解决这道题。注意,这里搜索时为了避免重复计算,我们每次递归只尝试一个位置,这样还能有效加速。具体请看代码。

代码

#include <cstdio>
#define maxn 20
using namespace std;bool mat[maxn][maxn];
int h, w, a, b, ans;inline bool valid(int x, int y)
{return !mat[x][y] && x >= 0 && x < h && y >= 0 && y < w;
}void dfs(int i, int j, int usedA, int usedB)
{if((usedA << 1) + usedB == h * w){ans ++;return;}if(i == h) return;int ni, nj;if(j == w - 1) ni = i + 1, nj = 0;else ni = i, nj = j + 1;if(mat[i][j]){dfs(ni, nj, usedA, usedB);return;}mat[i][j] = true;// Rectangle (A)if(usedA < a){if(valid(i, j + 1)){mat[i][j + 1] = true;dfs(ni, nj, usedA + 1, usedB);mat[i][j + 1] = false;}if(valid(i + 1, j)){mat[i + 1][j] = true;dfs(ni, nj, usedA + 1, usedB);mat[i + 1][j] = false;}}// Square (B)if(usedB < b) dfs(ni, nj, usedA, usedB + 1);mat[i][j] = false;
}int main()
{scanf("%d%d%d%d", &h, &w, &a, &b);dfs(0, 0, 0, 0);printf("%d\n", ans);return 0;
}

E - Filters

题目大意

给定三个整数序列A=(a1,a2,…,aN)A = (a_1, a_2, \dots, a_N)A=(a1​,a2​,…,aN​)、T=(t1,t2,…,tN)T = (t_1, t_2, \dots, t_N)T=(t1​,t2​,…,tN​)和X=(x1,x2,…,xQ)X = (x_1, x_2, \dots, x_Q)X=(x1​,x2​,…,xQ​)。
我们如下定义NNN个函数f1(x),f2(x),…,fN(x)f_1(x), f_2(x), \dots, f_N(x)f1​(x),f2​(x),…,fN​(x):
fi(x)={x+ai(ti=1)max⁡(x,ai)(ti=2)min⁡(x,ai)(ti=3)f_i(x) = \begin{cases} x + a_i & (t_i = 1)\\ \max(x, a_i) & (t_i = 2)\\ \min(x, a_i) & (t_i = 3)\\ \end{cases}fi​(x)=⎩⎨⎧​x+ai​max(x,ai​)min(x,ai​)​(ti​=1)(ti​=2)(ti​=3)​
对于每个i=1,2,…,Qi = 1, 2, \dots, Qi=1,2,…,Q,求fN(…f2(f1(xi))…)f_N( \dots f_2(f_1(x_i)) \dots )fN​(…f2​(f1​(xi​))…)。

1≤N,Q≤2×1051 \le N,Q \le 2 \times 10^51≤N,Q≤2×105
∣ai∣,∣xi∣≤109|a_i|,|x_i|\le 10^9∣ai​∣,∣xi​∣≤109
1≤ti≤31 \le t_i \le 31≤ti​≤3

输入格式

NNN
a1t1a_1~t_1a1​ t1​
a2t2a_2~t_2a2​ t2​
⋮\vdots⋮
aNtNa_N~t_NaN​ tN​
QQQ
x1x2…xqx_1~x_2~\dotsx x_qx1​ x2​ …xq​

输出格式

输出QQQ行。第iii行应该包含fN(…f2(f1(xi))…)f_N( \dots f_2(f_1(x_i)) \dots )fN​(…f2​(f1​(xi​))…)。

样例

样例输入

3
-10 2
10 1
10 3
5
-15 -10 -5 0 5

样例输出

0
0
5
10
10

在这里,f1(x)=max⁡(x,−10),f2(x)=x+10,f3(x)=min⁡(x,10)f_1(x) = \max(x, -10), f_2(x) = x + 10, f_3(x) = \min(x, 10)f1​(x)=max(x,−10),f2​(x)=x+10,f3​(x)=min(x,10),则有:

  • f3(f2(f1(−15)))=0f_3(f_2(f_1(-15))) = 0f3​(f2​(f1​(−15)))=0
  • f3(f2(f1(−10)))=0f_3(f_2(f_1(-10))) = 0f3​(f2​(f1​(−10)))=0
  • f3(f2(f1(−5)))=5f_3(f_2(f_1(-5))) = 5f3​(f2​(f1​(−5)))=5
  • f3(f2(f1(0)))=10f_3(f_2(f_1(0))) = 10f3​(f2​(f1​(0)))=10
  • f3(f2(f1(5)))=10f_3(f_2(f_1(5))) = 10f3​(f2​(f1​(5)))=10

分析

(参考AtCoder官方题解)
很容易想到,我们可以直接照做,即分别计算每个fN(…f2(f1(xi))…)f_N( \dots f_2(f_1(x_i)) \dots )fN​(…f2​(f1​(xi​))…)。但是,这样做的时间复杂度是O(NQ)\mathcal O(NQ)O(NQ),所以肯定会TLE
我们考虑它们的复合函数F(x)=fN(…f2(f1(xi))…)F(x)=f_N( \dots f_2(f_1(x_i)) \dots )F(x)=fN​(…f2​(f1​(xi​))…)在图上怎么表示。

  • 当ti=1t_i=1ti​=1,fif_ifi​是将图整体平移的操作;
  • 当ti=2t_i=2ti​=2,fif_ifi​是将图的最小值设为aia_iai​;
  • 当ti=3t_i=3ti​=3,fif_ifi​是将图的最大值设为aia_iai​。

所以,我们可以得到下图:

或者说,存在三个数a,b,ca,b,ca,b,c使得F(x)=min⁡(c,max⁡(b,x+a))F(x)=\min(c,\max(b,x+a))F(x)=min(c,max(b,x+a))。
关于a,b,ca,b,ca,b,c的具体计算请看代码。

代码

注意:这里的代码中的∞\infty∞(INF)一定不能直接设为long long的最大值,否则会溢出!

#include <cstdio>
#include <algorithm>
#include <climits>
using namespace std;typedef long long LL;
const LL INF = LLONG_MAX >> 1LL;int main()
{LL l = -INF, r = INF, add = 0LL;int n, q;scanf("%d", &n);while(n--){LL a, t;scanf("%lld%lld", &a, &t);if(t == 1) l += a, r += a, add += a;else if(t == 2) l = max(l, a), r = max(r, a);else l = min(l, a), r = min(r, a);}scanf("%d", &q);while(q--){LL x;scanf("%lld", &x);printf("%lld\n", clamp(x + add, l, r));}return 0;
}

AtCoder Beginner Contest 196 A~E题解相关推荐

  1. AtCoder Beginner Contest 246 A~E 题解 Bishop 2

    AtCoder Beginner Contest 246 A~E 题解 A Four Points 题意 给你矩形的三个顶点,输出剩下那个 思路 把横坐标和纵坐标分开,必会存在两个相同的数,横纵坐标就 ...

  2. AtCoder Beginner Contest 252 A~G 题解

    前言 这是我第一次写7题(A~G)的ABC题解,若有写得不好或者不到位的地方请多多指教,我将万分感激,感谢大家的支持! ABC252 A~G [A - ASCII code](https://atco ...

  3. AtCoder Beginner Contest 177 A~D 题解

    ABC177 A~D [A - Don't be late](https://atcoder.jp/contests/abc177/tasks/abc177_a) 题目大意 输入格式 输出格式 样例 ...

  4. AtCoder Beginner Contest 168 C~D题解

    ABC168 C&D [C - : (Colon)](https://atcoder.jp/contests/abc168/tasks/abc168_c) 题目大意 输入格式 输出格式 样例 ...

  5. AtCoder Beginner Contest 242 C~E 题解

    ABC242 C~E [C - 1111gal password](https://atcoder.jp/contests/abc242/tasks/abc242_c) 题目大意 输入格式 输出格式 ...

  6. AtCoder Beginner Contest 250 C~E 题解

    ABC250 C~E [C - Adjacent Swaps](https://atcoder.jp/contests/abc250/tasks/abc250_c) 题目大意 输入格式 输出格式 样例 ...

  7. AtCoder Beginner Contest 192 A~D题解

    ABC192 A~D [A - Star](https://atcoder.jp/contests/abc192/tasks/abc192_a) 题目大意 输入格式 输出格式 样例 分析 代码 [B ...

  8. AtCoder Beginner Contest 254 A~E 题解

    ABC254 A~E [A - Last Two Digits](https://atcoder.jp/contests/abc254/tasks/abc254_a) 题目大意 输入格式 输出格式 样 ...

  9. AtCoder Beginner Contest 205 A~E 题解

    ABC205 A~E [A - kcal](https://atcoder.jp/contests/abc205/tasks/abc205_a) 题目大意 输入格式 输出格式 样例 分析 代码 [B ...

最新文章

  1. 《用Python进行自然语言处理》第 11 章 语言数据管理
  2. Echange配置企业邮件收发策略
  3. 英伟达新卡皇3090Ti:功耗飙至450W换来性能涨11%
  4. component lists rendered with v-for should have explicit keys
  5. 鸟哥的Linux私房菜(服务器)- 第六章、 Linux 网络侦错
  6. 图像变清晰 图像放大 提高分辨率 提高清晰度
  7. python + pyqt5 UI和信号槽分离方法
  8. SQL中binary 和 varbinary的区别
  9. figcaption html5,HTML5 figcaption 标签
  10. python汉字排序_【IT专家】Python中文排序(转载)
  11. 拟阵:贪心原理(bzoj 3105: [cqoi2013]新Nim游戏)
  12. 【无人机控制】四旋翼飞行器飞行控制系统含Matlab源码
  13. 电路交换,报文交换和分组交换的区别?
  14. 姓名投票c语言未给定候选人,C语言上机
  15. 扩展名为ifo的文件怎么播放
  16. flink Too many fields referenced from an atomic type
  17. 迎合国家新政策,共享购联合共享经济,三方互利,消费增值
  18. 由一个骂评引发的作者产品体验报告-----我要集气
  19. python 调用 Intel realsense D415摄像头
  20. 看看谁还不会用【ARM汇编】求最大值

热门文章

  1. MFC 编程从入门到精通
  2. 安装LAPACK 动态库
  3. linux桌面管理器sddm,GDM, KDM, LightDM, SDDM的区别和安装配置
  4. java 8583报文解析_ISO8583报文工具类(组装和解析报文) | 学步园
  5. 【Alios-things笔记】EMW3060 UART串口
  6. 1月8日服务器例行维护公告,【维护】1月8日官方维护公告(正式服)
  7. java中构造方法的特征及其作用
  8. Backup Retention Policies
  9. AES 256 加密解密
  10. 纯HTML+CSS实现阿童木头像