题目链接

用火柴棍拼出最大的数,思维题,最后发现暴力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. Caliburn.Micro学习笔记(四)----IHandle<T>实现多语言功能

    Caliburn.Micro学习笔记目录 说一下IHandle<T>实现多语言功能 因为Caliburn.Micro是基于MvvM的UI与codebehind分离, binding可以是双 ...

  2. JQuery 获得div绝对,相对位置的坐标方法

    获取页面某一元素的绝对X,Y坐标 var X = $('#DivID').offset().top; var Y = $('#DivID').offset().left; 获取相对(父元素)位置: v ...

  3. 如何实时查看linux下的日志

    Linux日志文件在/var/log目录下,可以通过命令查看日志文件. 1,cat messages可以查看某个日志文件. 2,要达到实时更新,可以通过tail命令查看更新的数据,例如tail -f ...

  4. 基于MST的立体匹配及相关改进(A Non-Local Cost Aggregation Method for Stereo Matching)

    怀着很纠结的心情来总结这篇论文,这主要是因为作者提虽然供了源代码,但是我并没有仔细去深究他的code,只是把他的算法加进了自己的项目.希望以后有时间能把MST这一结构自己编程实现!! 论文题目是基于非 ...

  5. Github代理设置

    启用代理 git config --global http.proxy http://proxyuser:proxypwd@proxy.server.com:8080 git config --glo ...

  6. wildfly jboss 优化配置

    参考调优:http://www.mastertheboss.com/jboss-server/jboss-performance/jboss-as-7-performance-tuning?showa ...

  7. Flash调用麦克风

    import flash.events.ActivityEvent;import flash.media.Microphone;var deviceArray:Array = Microphone.n ...

  8. jQuery动态增删改查表格信息,可左键/右键提示

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  9. C#对文件/目录的操作:Path、File、Directory、FileStream、StreamReader、StreamWriter等类的浅析

    以下类的命名空间都是:System.I/0; 一.Path:主要对文件路径的操作! 常用方法: String path=@"C:\a\b\c\123.txt"; 1-1.Path. ...

  10. 主流ORM对比分析,莫人云亦云

    目前主流的ORM框架有Entity Framework,Dapper,NHibernate,NBear,Castle ActiveRecord,BATIS.NET六种,都是免费开源的.下边从官方支持性 ...