Codeforces 934D - A Determined Cleanup
934D - A Determined Cleanup
思路:
找规律,和k进制的求法差不多,答案的奇数位是p%k,偶数位如果p%k!=0,那么答案是k-p%k,否则为0。
代码:
#include<bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define mem(a,b) memset(a,b,sizeof(a))const int N=2e3+5; vector<int>ans; int main(){ios::sync_with_stdio(false);cin.tie(0);ll p,k;cin>>p>>k;int t=0;while(p){if(t%2==0)ans.pb(p%k),p/=k;else{if(p%k)ans.pb(k-p%k),p=p/k+1;else ans.pb(0),p=p/k;}t++;}cout<<ans.size()<<endl;for(int i=0;i<ans.size();i++)cout<<ans[i]<<' ';cout<<endl;return 0; }
转载于:https://www.cnblogs.com/widsom/p/8449499.html
Codeforces 934D - A Determined Cleanup相关推荐
- Codeforces Round #462 (Div. 2)题解
Codeforces Round #462 (Div. 2) B题--我固执的认为1e18是18位数,导致被hack,花了20分钟才检查出这个错误,很僵硬 Codeforces 934C 题意 给定一 ...
- Codeforces Gym 100513G G. FacePalm Accounting 暴力
G. FacePalm Accounting Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100513 ...
- Codeforces Round #331 (Div. 2) A. Wilbur and Swimming Pool 水题
A. Wilbur and Swimming Pool Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/conte ...
- Codeforces Round #299 (Div. 2) D. Tavas and Malekas kmp
题目链接: http://codeforces.com/problemset/problem/535/D D. Tavas and Malekas time limit per test2 secon ...
- Codeforces Round #597 (Div. 2) - BenFromHRBUST
Codeforces Round #597 (Div. 2) -----比赛传送门----- A - Good ol' Numbers Coloring Problem Description Con ...
- Codeforces Round #335 (Div. 2) D. Lazy Student 构造
D. Lazy Student Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/606/probl ...
- Codeforces Beta Round #2-A. Winner——算法笔记
题目链接:http://codeforces.com/problemset/problem/2/A 题目描述: The winner of the card game popular in Berla ...
- CodeForces 375D Tree and Queries
传送门:https://codeforces.com/problemset/problem/375/D 题意: 给你一颗有根树,树上每个节点都有其对应的颜色,有m次询问,每次问你以点v为父节点的子树内 ...
- 「日常训练」Bad Luck Island(Codeforces Round 301 Div.2 D)
题意与分析(CodeForces 540D) 是一道概率dp题. 不过我没把它当dp做... 我就是凭着概率的直觉写的,还好这题不算难. 这题的重点在于考虑概率:他们喜相逢的概率是多少?考虑超几何分布 ...
- 【codeforces 812C】Sagheer and Nubian Market
[题目链接]:http://codeforces.com/contest/812/problem/C [题意] 给你n个物品; 你可以选购k个物品;则 每个物品有一个基础价值; 然后还有一个附加价值; ...
最新文章
- java类接口的区别_【Java基础】java接口和类的区别-瑶瑶吖的回答
- 【Spring Web MVC】Spring Web MVC 注解开发环境搭建
- sys.stderr.write(f“ERROR: {exc}“) SyntaxError: invalid syntax错误
- fatal error C1083: 无法打开包括文件:“stdio.h
- [APP]- 找回Xcode7的代码折叠功能
- mondrain配置mysql_mondrian 4.7 源码部署(示例代码)
- Spring CGLlB动态代理
- 【论文笔记】K-plet Recurrent Neural Networks for Sequential Recommendation
- 文本导入ORACLE快速,Oracle批量导入文本文件快速的方法(sqlldr实现)
- oracle 触发器 实例
- 如何使用ESP8266、ESP8285做一个WiFi中继(WiFi信号放大器)
- (转载)c++builder/delphi中透明panel及透明窗口的实现方法_delphi教程
- 【python】小游戏程序——弹跳小球
- linux卸载nvdia驱动_Ubuntu 卸载 Nvidia 驱动和安装最新驱动
- 三层交换技术与链路聚合
- 台式电脑怎么装win10 win11重装win10系统
- Service与Android系统设计(5)-- libbinder
- 【JS组件系列】——表格组件神器:bootstrap table(二:父子表和行列调序)
- ios合并两张图片(叠加两张图片 重合两张图片)
- 服务器低功耗cpu性能,CPU走低功耗 难以解决服务器功耗问题