日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

2020牛客国庆集训派对day4 Jokewithpermutation

發布時間:2023/12/3 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 2020牛客国庆集训派对day4 Jokewithpermutation 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Jokewithpermutation

題目描述

Joey had saved a permutation of integers from 1 to n in a text file.
All the numbers were written as decimal numbers without leading
spaces. Then Joe made a practical joke on her: he removed all the
spaces in the file. Help Joey to restore the original permutation
after the Joe’s joke! 輸入描述: The input file contains a single line with
a single string — the Joey’s permutation without spaces. The Joey’s
permutation had at least 1 and at most 50 numbers. 輸出描述: Write a line
to the output file with the restored permutation. Don’t forget the
spaces! If there are several possible original permutations, write any
one of them.

示例1
輸入
復制

4111109876532

輸出
復制

4 1 11 10 9 8 7 6 5 3 2

備注:
Author: Mikhail Dvorkin

題意:

給你一串數,這串數字為n的全排列,問怎么將數分段格,使得成為n的全排列
看樣例4111109876532,可以為4 1 11 10 9 8 7 6 5 3 2

題解:

隊友做得,dfs暴力即可,就是假設當為一位數或者兩位數時,看看情況
詳細看代碼吧

代碼:

#include<bits/stdc++.h> #define maxn 6000 using namespace std; char a[maxn]; vector<int>ans; bool vis[maxn]; unordered_map<int,int>p; bool f=0; int s; void dfs(int n){if(f)return ;int size=strlen(a+1);if(n>size){printf("%d",ans[0]);for(int i=1;i<ans.size();i++){printf(" %d",ans[i]);}f=1;return ;}if(p[a[n]-'0']==0){p[a[n]-'0']=1;ans.push_back(a[n]-'0');dfs(n+1);ans.pop_back();p[a[n]-'0']=0;}if(f)return ;if(n<=size-1&&p[(a[n]-'0')*10+(a[n+1]-'0')]==0&&(a[n]-'0')*10+(a[n+1]-'0')<=s){p[(a[n]-'0')*10+(a[n+1]-'0')]=1;ans.push_back((a[n]-'0')*10+(a[n+1]-'0'));dfs(n+2);ans.pop_back();p[(a[n]-'0')*10+(a[n+1]-'0')]=0;}if(f)return ; } int main(){scanf("%s",a+1);s=strlen(a+1)>9?(strlen(a+1)-9)/2+9:strlen(a+1);dfs(1);return 0; }

總結

以上是生活随笔為你收集整理的2020牛客国庆集训派对day4 Jokewithpermutation的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。