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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

【Gym - 101612C】【2017-2018NEERC】Consonant Fencity(状压枚举,预处理)

發布時間:2023/12/10 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【Gym - 101612C】【2017-2018NEERC】Consonant Fencity(状压枚举,预处理) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題干:

把26個字母分成19個輔音字母和7個元音字母,讓你通過 將某些字母改為大寫狀態,使得字符串中連續的兩個大小寫狀態不同的輔音字母組成的字母對數量最多,輸出該狀態下的字符串。注意輸出的字符串中同一字母必須形態統一,也就是對于同一個字母,不能既有大寫狀態的,也有小寫狀態的。如果有多種可能的解,輸出任意一種。?

解題報告:

注意到除去元音字母,還剩下19個輔音字母,這樣我們第一步可以2^19枚舉變換的福音字母。

接下來首先想到的是O(n)的check,但是注意到其實需要統計的信息只是相鄰字母無序對而已,而無序對的種類一共19*19種。所以我們check的時候不需要跑一遍字符串,只需要統計著19*19個無序對數量即可。

總復雜度O(19 * 19 * 2^19)

AC代碼:

#include<cstdio> #include<iostream> #include<algorithm> #include<queue> #include<stack> #include<map> #include<vector> #include<set> #include<string> #include<cmath> #include<cstring> #define FF first #define SS second #define ll long long #define pb push_back #define pm make_pair using namespace std; typedef pair<int,int> PII; const int MAX = 1e6 + 5; const int up = 19; char s[MAX]; int cnt[226]; int num[666][666]; int buf[2],pos[666]; bool yy[555];//是元音則為1 //char biao[55]; int tot; int ok[222],ansok[222];//在本輪中選還是沒選 ll ans,anssta; int main() {freopen("consonant.in","r",stdin);freopen("consonant.out","w",stdout);yy['a']=yy['e']=yy['i']=yy['o']=yy['u']=yy['w']=yy['y']=1;for(char ch = 'a'; ch <= 'z'; ch++) {if(yy[ch] == 1) continue;pos[ch]=tot++;} // printf("%d\n",tot); // for(int i = 0; i<tot; i++) printf("%c ",biao[i]);scanf("%s",s+1);int len = strlen(s+1);for(int i = 2; i<=len; i++) {if(s[i] == s[i-1] || yy[s[i]] || yy[s[i-1]]) continue; // cnt[pos[s[i]]]++;cnt[pos[s[i-1]]]++;buf[0]=pos[s[i]];buf[1]=pos[s[i-1]];if(buf[0] > buf[1]) swap(buf[0],buf[1]);num[buf[0]][buf[1]]++;//已對應到0~18 }for(int sta = 0; sta<(1<<up); sta++) {ll cur = 0;for(int bit = 0; bit<up; bit++) {if(sta & (1<<bit)) ok[bit]=1;else ok[bit]=0;}for(int i = 0; i<up; i++) {for(int j = i+1; j<up; j++) {//枚舉不同的兩個數 if(ok[i] + ok[j] == 1) cur += num[i][j];}}if(cur > ans) {ans = cur;for(int bit = 0; bit<up; bit++) ansok[bit] = ok[bit];}} for(int i = 1; i<=len; i++) {if(ansok[pos[s[i]]]) printf("%c",s[i] + 'A'-'a');else printf("%c",s[i]);}return 0; } //qqqqq

?

總結

以上是生活随笔為你收集整理的【Gym - 101612C】【2017-2018NEERC】Consonant Fencity(状压枚举,预处理)的全部內容,希望文章能夠幫你解決所遇到的問題。

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