Codeforces Gym - 101102B - The Little Match Girl
1 second
256 megabytes
standard input
standard output
Using at most 7 matchsticks, you can draw any of the 10 digits as in the following picture:
The picture shows how many sticks you need to draw each of the digits.
Zaytoonah has a number that consists of N digits. She wants to move some sticks (zero or more) to maximize the number. Note that she doesn’t want to remove any of the sticks, she will only move them from one place to another within the N digits. She also doesn’t want to add new digits as N is her lucky number.
Can you help Zaytoonah maximize her number?
The first line of input contains a single integer T, the number of test cases.
Each test case contains a single integer N (1 ≤ N ≤ 105), followed by a space, then N digits that represent the number Zaytoonah currently has.
For each test case, print on a single line the maximum number Zaytoonah can get.
3
1 3
3 512
3 079
5
977
997
题意:略。
方法:贪心,先求出总的火柴数,再从最大数字开始贪,最后一个单独输出。
代码:
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
const int N=1e5+;
int a[]={
,,,,,,,,,
};
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n;
char s[N];
int sum=;
scanf("%d %s",&n,s);
for(int i=;i<n;i++)
{
sum+=a[s[i]-''];
}
for(int i=;i<n;i++)
{
for(int j=;j>=;j--)
{
int temp=sum-a[j];
if(temp>=*(n-i)&&temp<=*(n-i))
{
cout<<j;
sum-=a[j];
break;
}
}
}
for(int i=;i>=;i--)
{
if(sum==a[i])
{
cout<<i<<endl;
break;
}
}
}
return ;
}
Codeforces Gym - 101102B - The Little Match Girl的更多相关文章
- Gym 101102B The Little Match Girl(贪心+规律)
		
这个题目的做法不止一种,solve1:每个数字使用的火柴棒都在2~7之间,而且是连续的,就是2-7之前没有空着的数.这样就有一个结论,在下界为l,上界为r的情况下,假设有n个数,那么火柴棒总数一定在n ...
 - Codeforces Gym 101252D&&floyd判圈算法学习笔记
		
一句话题意:x0=1,xi+1=(Axi+xi%B)%C,如果x序列中存在最早的两个相同的元素,输出第二次出现的位置,若在2e7内无解则输出-1. 题解:都不到100天就AFO了才来学这floyd判圈 ...
 - Codeforces Gym 101190M Mole Tunnels - 费用流
		
题目传送门 传送门 题目大意 $m$只鼹鼠有$n$个巢穴,$n - 1$条长度为$1$的通道将它们连通且第$i(i > 1)$个巢穴与第$\left\lfloor \frac{i}{2}\rig ...
 - Codeforces Gym 101623A - 动态规划
		
题目传送门 传送门 题目大意 给定一个长度为$n$的序列,要求划分成最少的段数,然后将这些段排序使得新序列单调不减. 考虑将相邻的相等的数缩成一个数. 假设没有分成了$n$段,考虑最少能够减少多少划分 ...
 - 【Codeforces Gym 100725K】Key Insertion
		
Codeforces Gym 100725K 题意:给定一个初始全0的序列,然后给\(n\)个查询,每一次调用\(Insert(L_i,i)\),其中\(Insert(L,K)\)表示在第L位插入K, ...
 - Codeforces gym 101343 J.Husam and the Broken Present 2【状压dp】
		
2017 JUST Programming Contest 2.0 题目链接:Codeforces gym 101343 J.Husam and the Broken Present 2 J. Hu ...
 - codeforces gym 100553I
		
codeforces gym 100553I solution 令a[i]表示位置i的船的编号 研究可以发现,应是从中间开始,往两边跳.... 于是就是一个点往两边的最长下降子序列之和减一 魔改树状数 ...
 - CodeForces Gym 100213F Counterfeit Money
		
CodeForces Gym题目页面传送门 有\(1\)个\(n1\times m1\)的字符矩阵\(a\)和\(1\)个\(n2\times m2\)的字符矩阵\(b\),求\(a,b\)的最大公共 ...
 - Codeforces GYM 100876 J - Buying roads 题解
		
Codeforces GYM 100876 J - Buying roads 题解 才不是因为有了图床来测试一下呢,哼( 题意 给你\(N\)个点,\(M\)条带权边的无向图,选出\(K\)条边,使得 ...
 
随机推荐
- socket:10038错误
			
转自:http://blog.csdn.net/chen495810242/article/details/42029825 winSock的一个bug:当closesocket多次错误使用时会导致问 ...
 - linux centos6.8搭建 jdk 环境
			
1. 上官网下载jdk1.8的包 http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html ...
 - http状态码204/206/200/302/303/307
			
HTTP的状态码有很多种,主要有1xx(临时响应).2xx(成功).3xx(已重定向).4xx(请求错误)以及5xx(服务器错误)五个大类,每个大类还对应一些具体的分类.平时我们接触比较多的是200. ...
 - axure rp 8.0注册码(亲测)
			
今天在看一需求原型时,发现其他部门发过来是8.0版的,老的7不能用,找了个亲测可用的验证码. License:米 业成 (STUDENT)Key:nFmqBBvEqdvbiUjy8NZiyWiRSg3 ...
 - android之发送Get或Post请求至服务器接口
			
import java.io.BufferedReader; import java.io.ByteArrayOutputStream; import java.io.IOException; imp ...
 - promql查询表达式
			
Basics 即时矢量选择器 =:匹配与标签相等的内容!=:不匹配与标签相等的内容=~: 根据正则表达式匹配与标签符合的内容!~:根据正则表达式不匹配与标签符合的内容 示例: http_request ...
 - [c/c++] programming之路(2)、kill QQ,弹出系统对话框,吃内存等
			
一.删除文件 二.盗取密码的原理 #include<stdlib.h> //杀掉QQ,然后提示网络故障,请重新登陆,弹出高仿界面,获取账号密码,然后打开QQ进行登录 void main() ...
 - CentOS 7下搭建配置 SVN 服务器
			
原文链接:https://www.cnblogs.com/tdalcn/p/6937714.html 同步:http://blog.csdn.net/u011884440/article/detail ...
 - xlrd、xlwt 操作excel表格详解
			
转自:https://www.cnblogs.com/jiablogs/p/9141414.html python操作excel主要用到xlrd和xlwt这两个库,即xlrd是读excel,xlwt是 ...
 - Python3 tkinter基础 Frame bind 敲击键盘事件 将按键打印到console中
			
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...