联系 Contact
生活随笔
收集整理的這篇文章主要介紹了
联系 Contact
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
https://www.luogu.org/problemnew/show/P2724
題意:輸出多少頻率最多的序列。
題解:
輸出
排序
C++版本一
題解:map+vector+sort+枚舉
/* *@Author: STZG *@Language: C++ */ #include <bits/stdc++.h> #include<iostream> #include<algorithm> #include<cstdlib> #include<cstring> #include<cstdio> #include<string> #include<vector> #include<bitset> #include<queue> #include<deque> #include<stack> #include<cmath> #include<list> #include<map> #include<set> //#define DEBUG #define RI register int #define endl "\n" using namespace std; typedef long long ll; //typedef __int128 lll; const int N=200000+10; const int M=200000; const int MOD=1e9+7; const double PI = acos(-1.0); const double EXP = 1E-8; const int INF = 0x3f3f3f3f; int t,n,m,k,p,l,r,u,v; int ans,cnt,flag,sum; string str,temp; map<string,int>mp; vector<string>V[N]; struct node{string str;int cnt;bool operator <(const node &S)const{if(cnt==S.cnt){if(str.size()==S.str.size()){return str<S.str;}return str.size()<S.str.size();}return cnt>S.cnt;}}e[N]; int main() { #ifdef DEBUGfreopen("input.in", "r", stdin);//freopen("output.out", "w", stdout); #endif//ios::sync_with_stdio(false);//cin.tie(0);//cout.tie(0);//scanf("%d",&t);//while(t--){scanf("%d%d%d",&n,&m,&k);while(cin>>temp){str+=temp;}cin>>str;for(int i=n;i<=m;i++){for(int j=0;i+j<=str.size();j++){string temp=str.substr(j,i);if(!mp[temp]){mp[temp]=++sum;e[sum].str=temp;}int id=mp[temp];e[id].cnt++;}}sort(e+1,e+sum+1);for(int i=1;i<=sum;i++){V[e[i].cnt].push_back(e[i].str);}for(int i=M;i>0&&cnt<k;i--){if(V[i].size()){cout<<i<<endl;cnt++;for(int j=0;j<V[i].size();j++){cout<<V[i][j]<<((j+1)%6==0||j==V[i].size()-1?'\n':' ');}}}//}#ifdef DEBUGprintf("Time cost : %lf s\n",(double)clock()/CLOCKS_PER_SEC); #endif//cout << "Hello world!" << endl;return 0; }C++版本二
題解:狀態壓縮+DP
/* ID: K wth PROG: contact LANG: C++ */ #include <bits/stdc++.h> using namespace std; char s[300000]; int hz [1<<13]; int l,r,n,m; struct note {int x;int y;int z;note(int x=0,int y=0,int z=0):x(x),y(y),z(z) {}; }; vector<note> v; bool cmp(note x,note y) {return x.y>y.y || x.y==y.y && (x.z<y.z || x.z==y.z && x.x<y.x); } void work(int x,int lon) {int mod=(1<<lon)-1;while(lon+1){putchar('0'+(x>>lon));x&=mod;mod>>=1;lon--;} } int main() {scanf("%d %d %d",&l,&r,&n);for(int i=0;scanf("\n%s",s+i)!=-1;i+=80) ; // printf("%s\n\n",s);return 0;r=min(m=strlen(s) , r);for(int i=0,zhi=0;i<r;i++){zhi=(zhi<<1)|(s[i]-'0');if(i>=l-1){int mod=(1<<(i+1))-1,z=zhi;memset(hz,0,sizeof(hz));hz[z]=1;for(int j=i+1;j<m;j++){z=((z<<1)|(s[j]-'0'))&mod;hz[z]++;}for(int j=0;j<=mod;j++)if(hz[j])v.push_back(note(j,hz[j],i));}}sort(v.begin(),v.end(),cmp);for(int i=0,last=1<<18,j=0,have=0;i<v.size();i++,have++){// cout<<"test:"<<v[i].x<<v[i].y<<v[i].z<<endl;if(v[i].y<last){last=v[i].y;if(j++==n || !last) break;if(i) putchar('\n');have=0;printf("%d\n",last);}else if(have==6) putchar('\n'),have=0;else putchar(' ');work(v[i].x,v[i].z);}putchar('\n'); }?
總結
以上是生活随笔為你收集整理的联系 Contact的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 丑数 Humble Numbers
- 下一篇: 邮票 Stamps