Problem B: Ternarian Weights
大致题意:使用三进制砝码采取相应的措施衡量出给定的数字
主要思路:三进制,如果 大于 2 向前进位,之前一直没写好放弃了,这次终于写好了……
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <map>
#include <cmath>
#include <cstring>
#include <string>
#include <queue>
#include <stack>
#include <cctype> const double Pi = atan() * ; using namespace std;
long long base[] = {,,,,,,,,,,,,,,,,,,,,,};
int a[];
int tt[];
int main()
{
//freopen("input.in","r",stdin);
//freopen("output.in","w",stdout);
int n;
cin >> n;
while(n--){
int x;
cin >> x;
memset(a,,sizeof(a));
memset(tt,,sizeof(tt));
int tmp = x;
while(tmp){
a[++a[] ] = tmp % ;
tmp /= ;
}
for(int i = ;i <= a[];i++){
if(a[i] == ){
a[i+]++;
a[] = max(i+,a[]);
tt[ ++tt[] ] = i;
a[i] = ;
}
if(a[i] == ){
a[i+]++;
a[] = max(i+,a[]);
a[i] = ;
}
}
cout << "left pan:";
for(int i = tt[];i > ;i--){
cout << " " << base[ tt[i] ];
}
cout << endl;
cout << "right pan:";
for(int i = a[];i > ;i--){
if(!a[i])
continue;
cout << " " << base[i];
}
cout << endl;
if(n)
cout << endl;
}
return ;
}
Problem B: Ternarian Weights的更多相关文章
- HNU 13073 Ternarian Weights 解题报告
本题大意: 用天平对一物品进行称重,现有重量不同的砝码,砝码的重量分别为:1,3,9,27,..,3^n.(n<20) 天平的右侧放砝码,左侧放物品或物品和砝码,使得左右两边的重量相等. 现有一 ...
- Problem F Free Weights
二分答案. 思路:对于二分给定的mid,即当前允许移动的最大重量,我们可以把小于改重量的标记一下,然后把没有标记的按照顺序放到另一个数组,然后判断是否满足两两相同. #include<bits/ ...
- Deep Learning in a Nutshell: History and Training
Deep Learning in a Nutshell: History and Training This series of blog posts aims to provide an intui ...
- CF #296 (Div. 1) B. Clique Problem 贪心(构造)
B. Clique Problem time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- Codeforces #270 D. Design Tutorial: Inverse the Problem
http://codeforces.com/contest/472/problem/D D. Design Tutorial: Inverse the Problem time limit per t ...
- [codeforces 528]B. Clique Problem
[codeforces 528]B. Clique Problem 试题描述 The clique problem is one of the most well-known NP-complete ...
- UVa 10154 - Weights and Measures
UVa 10154 - Weights and Measures I know, up on top you are seeing great sights, But down at the bot ...
- poj 1679 http://poj.org/problem?id=1679
http://poj.org/problem?id=1679 The Unique MST Time Limit: 1000MS Memory Limit: 10000K Total Submis ...
- Codeforces Gym 100342H Problem H. Hard Test 构造题,卡迪杰斯特拉
Problem H. Hard TestTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100342/at ...
随机推荐
- django 新闻编辑笔记
url(r'^news_manage/edit/$',views.news_edit,name='edit') url配置 <a href="/management/news_mana ...
- JAVA爬虫 WebCollector
JAVA爬虫 WebCollector 爬虫简介: WebCollector是一个无须配置.便于二次开发的JAVA爬虫框架(内核),它提供精简的的API,只需少量代码即可实现一个功能强大的爬虫. 爬虫 ...
- “快的打车”创始人陈伟星的新项目招人啦,高薪急招Java服务端/Android/Ios 客户端研发工程师/ mysql DBA/ app市场推广专家,欢迎大家加入我们的团队! - V2EX
"快的打车"创始人陈伟星的新项目招人啦,高薪急招Java服务端/Android/Ios 客户端研发工程师/ mysql DBA/ app市场推广专家,欢迎大家加入我们的团队! - ...
- swift 关于 toolbar 学习笔记
import UIKit class ViewController: UIViewController { @IBOutlet weak var toolBar: UIToolbar! @IBOutl ...
- 数据类型及其空间大小,vs2012实测
#include "stdafx.h" #include <stdio.h> #include "common.h" #include " ...
- 你知道hover、active这四个伪类为什么要按顺序写吗
刨根问底,你知道:hover等4个伪类为什么要按顺序排列吗 引言 :link,:visited,:hover,:active这4个伪类大家都不陌生,4个伪类要按照LvHa这个爱恨原则来排(外国友人起的 ...
- Xcode的Hello World(简单易懂)
http://www.cocoachina.com/industry/20131121/7392.html http://objccn.io/issue-6-3/
- spark论坛
http://spark.apache.org/ http://bbs.csdn.net/forums/spark http://spark.csdn.net/ http://tieba.baidu. ...
- android 打包 /${zipalign}" error=2, No such file or directory
当我更新完android L proview之后我的打包出问题了,报错/${zipalign}" error=2, No such file or directory 排查了一下午才知道 近 ...
- Swift - 后台获取数据(Background Fetch)的实现
前面讲了如何让程序申请后台短时运行.但这个额外延长的时间毕竟有限.所以从iOS7起又引入两种在后台运行任务的方式:后台获取和后台通知. 1,后台获取介绍 后台获取(Background Fetch)是 ...