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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

hihocoder 1251 Today Is a Rainy Day 2015北京区域赛C

發布時間:2023/12/18 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 hihocoder 1251 Today Is a Rainy Day 2015北京区域赛C 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
// hihocoder 1251 Today Is a Rainy Day // 題目大意 // 兩個最大長度為110的只含123456這六種字符 // 的字符串,有兩種操作: // 1)將一個字符轉換成另一個 // 2)將一種字符轉換成另一個 // // 解題思路: // // 首先我們要明白,2操作比1操作改變的字符要多很多 // 這樣,如果1操作在2操作之前,;不如2在1之前,修改的范圍 // 更大,這樣,我們可以預處理出123456的映射關系,用一個 // 6位的6進制.(挺巧妙)總共的復雜度6的6次方大概是50000 // 用一個bfs就好,之后再找到單個的不一樣的. // // 感悟: // // 比賽的時候,雖然知道是bfs搜索,但是沒有想到只要 // 從123456這6個映射出發就可以了,哎,太年輕了,還是不到家 // 繼續加油吧~~~這題過了,可就是銀牌了,哎,遺憾,來年再戰! // 大神就是大神,蒟蒻就是蒟蒻#include <cstring> #include <algorithm> #include <iostream> #include <cstdio> #include <cmath> #include <string> #include <vector> #include <queue> #include <ctime> #include <cstdlib> #define For(x,a,b,c) for (int x = a; x <= b; x += c) #define Ffor(x,a,b,c) for (int x = a; x >= b; x -= c) #define cls(x,a) memset(x,a,sizeof(x)) using namespace std; typedef long long ll;const int MAX_N = 50000 + 8;const int INF = 0x3f3f3f3f; const ll MOD = 1e12;char a[200],b[200];int dp[MAX_N]; int f[10][10]; int ct[10]; int getId(int s[]){int x = 0;for (int i = 0 ;i < 6 ;i ++)x = x * 6 + s[i];return x; }void get_R(int x,int s[]){for (int i = 5;i >= 0;i --){s[i] = x % 6;x /= 6;} }void init(){cls(dp,0x3f);queue<int> que;int c[10];for (int i = 0 ; i < 6;i ++)c[i] = i;int s = getId(c);que.push(s);dp[s] = 0;int tmp[10];while(!que.empty()){s = que.front();que.pop();// cout << x++ << endl;get_R(s,c);for (int i = 0;i < 6 ;i ++)for (int j = 0 ;j < 6 ;j ++){memcpy(tmp,c,sizeof(tmp));for (int k = 0 ; k < 6 ; k ++)if (tmp[k] == i)tmp[k] = j;int u = getId(tmp);if (dp[u] > dp[s] + 1){dp[u] = dp[s] + 1;que.push(u);}}} }void solve(){int len = strlen(a);cls(ct,0);cls(f,0);for (int i = 0 ;i < len; i ++){ct[b[i]-'1']++;f[b[i]-'1'][a[i]-'1']++;}int mx = len;int t[10];for (int i = 0 ;i < MAX_N;i ++){int sum = dp[i];get_R(i,t);for (int j = 0;j < 6;j ++){sum += ct[j] - f[j][t[j]];}mx = min(mx,sum);}cout << mx << endl; }int main(){ios::sync_with_stdio(false);//freopen("1.in","r",stdin);init();while(cin >> a >> b){solve(); }return 0; }

總結

以上是生活随笔為你收集整理的hihocoder 1251 Today Is a Rainy Day 2015北京区域赛C的全部內容,希望文章能夠幫你解決所遇到的問題。

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