codeforces 792C. Divide by Three】的更多相关文章

题目链接:codeforces 792C. Divide by Three 今天队友翻了个大神的代码来问,我又想了遍这题,感觉很好,这代码除了有点长,思路还是清晰易懂,我就加点注释存一下...分类吧.删除一个数字模3为M的或删除两个模3为3-M的(还有一些要删零),具体看代码. #include<cstdio> #include<cstring> #include<algorithm> #include<iostream> #include<strin…
C. Divide by Three time limit per test: 1 second memory limit per test: 256 megabytes input: standard input output: standard output A positive integer number n is written on a blackboard. It consists of not more than 105 digits. You have to transform…
删除最少的数位和前缀0,使得剩下的数能被3整除 等价于各数位数字之和能被3整除. 当前数位和可能是 0, 1, 2(mod 3) 0: 直接处理 1: 删除一个a[i]%3 == 1 或者 两个a[i]%3 == 2 2: 同1 对于删完的数列,去掉前置0(只剩前置0就当作0) 若删啥都不满足,则判断原数列中有没有0,不然就输出-1 #include <bits/stdc++.h> using namespace std; ; char s[MAXN]; int a[MAXN], n; str…
[题目链接]:http://codeforces.com/contest/792/problem/C [题意] 让你删掉最少的数字使得剩下的数字%3==0 [题解] 看代码..内置题解了现在. [完整代码] #include <bits/stdc++.h> using namespace std; #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 #define LL long long #define rep1(i,a…
A positive integer number n is written on a blackboard. It consists of not more than 105 digits. You have to transform it into a beautiful number by erasing some of the digits, and you want to erase as few digits as possible. The number is called bea…
题目链接:http://codeforces.com/problemset/problem/1176/A 思路:贪心,对第二个操作进行俩次等于将n变成n/3,第三个操作同理,我们将n不断除以2,再除以3,最后除以5,判断最后是否等于1即可. AC代码: #include<iostream> using namespace std; long long n,ans; int main(){ int T; cin >> T; while(T--){ cin >> n; an…
  Polycarp likes to play with numbers. He takes some integer number xx, writes it down on the board, and then performs with it n−1n−1operations of the two kinds: divide the number xx by 33 (xx must be divisible by 33); multiply the number xx by 22. A…
Codeforces 题目传送门 & 洛谷题目传送门 显然,直接暴力枚举是不可能的. 考虑将点按横纵坐标奇偶性分组,记 \(S_{i,j}=\{t|x_t\equiv i\pmod{2},y_t\equiv j\pmod{2}\}(i,j\in[0,1])\),说白了就是横坐标为偶数.纵坐标为偶数:横坐标为偶数.纵坐标为奇数:横坐标为奇数.纵坐标为偶数:横坐标为奇数.纵坐标为奇数的点集. 然后考虑以下算法: 若 \(S_{0,0},S_{1,1}\) 以及 \(S_{0,1},S_{1,0}\)…
题意:给出一个由0到9数字构成的字符串,要求删去最少的数位,使得这个字符串代表的数能被3整除,同时要求不能有前导零,并且至少有一位(比如数字11,删去两个1后就没有数位了,所以不符合).如果能够处理出符合要求的字符串,输出之,否则输出-1. 解题思路:(这种题如果让我比赛做肯定写不出来,,细节太多了,磕磕碰碰看着数据改了好几次才勉强过的) 首先可以想到的就是,要使能被3整除,各数字位的和能被3整除即可.设各数字位和为sum,并且使sum%=3,那么sum就只能是1或者2(如果是0那么直接输出即可…
You are given an integer nn. You can perform any of the following operations with this number an arbitrary (possibly, zero) number of times: Replace nn with n2n2 if nn is divisible by 22; Replace nn with 2n32n3 if nn is divisible by 33; Replace nn wi…