博文

U173215 a+b and a*b without +-*/

        a+b and a*b without +-*/    给定 $a,b$ ,求 $a+b,a \times b$ 。   但是你键盘上的 +-*/ 键坏了。也就是说,你的代码中不能含有 '+', '-', '*', '/' 。   对于 $60\%$ 的数据, $1 \leq a,b \leq 10^9$ 。   对于所有数据, $1 \leq a,b \leq 10^{10^3}$ 。      60pts 的部分分答案不会超过 long long 范围,可以用位运算实现。   考虑加法二进制不进位的情况, $a+b = a \oplus b$ 。   而对于 $a,b$ 的每一位 $bit$,只有当 $a_{bit} = b_{bit} = 1$ 即 $a_{bit} \land b_{bit} = 1$ 时才会进位。所有要进的位便是 $a \land b$ 。   再用左移运算符来模拟进位。所以 $a+b = (a \oplus b)+((a \land b) << 1)$ ,后者的加法运算是可以递归实现的: inline long long add(long long a,long long b) { return b ?add(a^b,(a&b) << 1):a; }   乘法的实现则可以利用快速乘的思想,即 $a*b = a*(b/2)*2$ ,后者的乘法运算也是可以递归实现的: inline long long mul(int a,int b) { long long res=b ?mul(a,b >> 1) << 1:0; return b&1 ?add(res,a):res; }   代码总体长度 300B 左右。     满分做法需要将高精度模板改写,主要考察对字符串的理解运用。   高精度的思想即按位运算(这里的位指十进制的位且默认从第 $1$ 位开始)。   如果没有想到 60pts 的做法并实现对 $10$ 的除法运算(可以二分结果实现,想法来源于  Loxilante  ),需要 打表 出 0~9 的整数相加与相乘的结果。   下面代码中用 $ad,nx,mu,ca$ 数组分别表示相加结果

ATC ABC176

图片
本场ABC难度 from  AtCoder Problems A - Takoyaki  Editorial  /  Time Limit: 2 sec / Memory Limit: 1024 MB Problem Statement Takahashi loves takoyaki - a ball-shaped snack. With a takoyaki machine, he can make at most $X$ pieces of takoyaki at a time, taking $T$ minutes regardless of the number of pieces to make. How long does it take to make $N$  takoyaki? Constraints $1 \leq N,X,T \leq 1000$ All values in input are integers.                     Takahashi一次可以做$X$个章鱼烧,需要花费$T$分钟,求出做$N$个章鱼烧Takahashi需要的时间。                    我们只需求出Takahashi需要做几次章鱼烧(即$\left(N-1)\right/X+1$次),再将次数$\times T$就好了。      #include <bits/stdc++.h> using   namespace   std;      int   n,x,t;       int   main() {      scanf ( "%d%d%d" ,&n,&x,&t);      printf ( "%d\n" ,((n-1)/x+1)*t);      return   0; } B - Multiple of 9  Editorial  /  Time Limit: 2 sec / Memory Limit: 1024 MB Problem Statement An integer $N$    is a multiple of $9$   if and only if the sum of the digits in the decimal