码迷,mamicode.com
首页 > 其他好文 > 详细

Gym - 101102B

时间:2018-01-22 15:18:26      阅读:143      评论:0      收藏:0      [点我收藏+]

标签:name   []   markdown   using   algo   class   body   efi   clu   

注意到使用的代价均是2-7连续的,直接暴力必然有解

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<vector>
#define rep(i,j,k) for(int i=j;i<=k;i++)
#define rrep(i,j,k) for(int i=j;i>=k;i--)
using namespace std;
const int maxn = 1e5+11;
const int oo = 0x3f3f3f3f;
int a[]={6,2,5,5,4,5,6,3,7,6};
char str[maxn];
int main(){
    ios::sync_with_stdio(0);
    int N,T; cin>>T;
    while(T--){
        cin>>N>>str;
        int tot=0;
        rep(i,0,N-1) tot+=a[str[i]-‘0‘];
        int tmp=tot;
        rep(i,1,N){
            rrep(j,9,0){
                int t=tot-a[j];
                if(t>=2*(N-i)&&t<=7*(N-i)){//note
                    cout<<j;
                    tot=t;
                    break;
                }
            }
        }
        cout<<endl;
    }
    return 0;
}

Gym - 101102B

标签:name   []   markdown   using   algo   class   body   efi   clu   

原文地址:https://www.cnblogs.com/caturra/p/8329036.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!