题目链接

用火柴棍拼出最大的数,思维题,最后发现暴力1e7刚刚不会超时。

就是看如果这个位置放置尽可能大的数,剩余的火柴数够不够或者多不多。

够不够就是lefts>=leftn*2,多不多就是lefts<=leftn*7。

#include <bits/stdc++.h>
using namespace std;
int a[]={,,,,,,,,,};
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int len;
char c[];
scanf("%d%s",&len,c);
int sum=;
for(int i=;i<len;i++)
sum+=a[c[i]-''];
for(int i=;i<len;i++) {
for(int j=;j>=;j--) {
int lefts = sum-a[j];
int leftn = len-i-;
//printf("%d\n",lefts);
if(leftn*<=lefts&&lefts<=leftn*) {
putchar(''+j);
sum = lefts;
break;
}
}
}
puts("");
}
return ;
}

Gym - 101102B的更多相关文章

  1. Gym 101102B The Little Match Girl(贪心+规律)

    这个题目的做法不止一种,solve1:每个数字使用的火柴棒都在2~7之间,而且是连续的,就是2-7之前没有空着的数.这样就有一个结论,在下界为l,上界为r的情况下,假设有n个数,那么火柴棒总数一定在n ...

  2. Codeforces Gym - 101102B - The Little Match Girl

    B. The Little Match Girl time limit per test 1 second memory limit per test 256 megabytes input stan ...

  3. ACM: Gym 101047M Removing coins in Kem Kadrãn - 暴力

     Gym 101047M Removing coins in Kem Kadrãn Time Limit:2000MS     Memory Limit:65536KB     64bit IO Fo ...

  4. ACM: Gym 101047K Training with Phuket's larvae - 思维题

     Gym 101047K Training with Phuket's larvae Time Limit:2000MS     Memory Limit:65536KB     64bit IO F ...

  5. ACM: Gym 101047E Escape from Ayutthaya - BFS

    Gym 101047E Escape from Ayutthaya Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I6 ...

  6. ACM: Gym 101047B Renzo and the palindromic decoration - 手速题

     Gym 101047B  Renzo and the palindromic decoration Time Limit:2000MS     Memory Limit:65536KB     64 ...

  7. Gym 101102J---Divisible Numbers(反推技巧题)

    题目链接 http://codeforces.com/gym/101102/problem/J Description standard input/output You are given an a ...

  8. Gym 100917J---Judgement(01背包+bitset)

    题目链接 http://codeforces.com/gym/100917/problem/J Description standard input/outputStatements The jury ...

  9. Gym 100917J---dir -C(RMQ--ST)

    题目链接 http://codeforces.com/gym/100917/problem/D problem description Famous Berland coder and IT mana ...

随机推荐

  1. knockoutJS学习笔记08:表单域绑定

    前面的绑定都是用在基本标签上,这章主要讲表单域标签的绑定. 一.value 绑定 绑定标签:input text.textarea. <p>用户名:<input type=" ...

  2. Android开发的菜鸟小记

    1.主线程异常:添加网络连接: 2.权限异常: 3.空指针异常:NullException: 添加网络权限: DEBUG:Connected to the target VM, address: 'l ...

  3. windows2012 iis配置

    1.打开“组策略” 单击任务栏里的“windows powershell”, 键入 gpedit.msc,然后按 Enter. 2.修改windows 更新源为未配置.“计算机配置”---“管理模板” ...

  4. [Django 2]第一个django应用

    1)增加应用 python3 manage.py startapp app-name 2. settings.py中,“INSTALLED_APPS”添加应用名称. 3. 在templates中新增网 ...

  5. 1323 union解题报告

    http://codeup.cn/problem.php?id=1323 1323: 算法2-1:集合union 时间限制: 1 Sec 内存限制: 32 MB 提交: 2884 解决: 688 题目 ...

  6. OC中的@property详解

    简介: @property 生成了变量的get set 方法,同时指定了变量名称. 例如@property (nonatomic,strong) NSString *name;表示生成了_name私有 ...

  7. jquery源码中的(function(window, undefined){})(window)【转】

    (function( window, undefined ) {})(window);这个,为什么要将window和undefined作为参数传给它? (function( $, undefined ...

  8. 文本框 textarea 动态显示行数(简单文本编辑器)

    工作需求做一个文本编辑器简单的. 右边输入文字,左边会显示相应的代码行.清空也会变为1. 废话不多说上代码,自己理解. <style type="text/css"> ...

  9. Codeforces Round #377 (Div. 2) B. Cormen — The Best Friend Of a Man(贪心)

     传送门 Description Recently a dog was bought for Polycarp. The dog's name is Cormen. Now Polycarp has ...

  10. Day4-python基础之函数

    本次学习内容: 字典查询快的原因 字符编码 函数定义 局部变量.全局变量 返回值 嵌套函数 递归(二分查找) 三元运算 map lamba 函数式编程 高阶函数 内置函数 字典查询快的原因: 字典占用 ...