Codeforces 1176A Divide it!】的更多相关文章

题目链接: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…
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…
题目链接:codeforces 792C. Divide by Three 今天队友翻了个大神的代码来问,我又想了遍这题,感觉很好,这代码除了有点长,思路还是清晰易懂,我就加点注释存一下...分类吧.删除一个数字模3为M的或删除两个模3为3-M的(还有一些要删零),具体看代码. #include<cstdio> #include<cstring> #include<algorithm> #include<iostream> #include<strin…
题目: 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 n…
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…
  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,使得剩下的数能被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…
  计蒜客)翻硬币 //暴力匹配 #include<cstdio> #include<cstring> #define CLR(a, b) memset((a), (b), sizeof((a))) using namespace std; int n, m, t; int main() { int i, j, x; scanf("%d", &t); while(t--) { scanf("%d%d", &n, &m)…
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−1 operations of the two kinds: divide the number xx by 33 (xx must be divisible by 33); multiply the number xx by 22. Af…