GESP2023.6真題 圖像壓縮講解
2023-06-17 15:36 作者:JamesAlanE | 我要投稿

有沒有大佬幫忙看一下,不知道怎么回事只有60,感覺寫得都對(duì)的啊,是數(shù)據(jù)有問題還是什么?謝謝了??

- #include<bits/stdc++.h>
- using?namespace?std;
- int?n;
- char?a[20]="0123456789ABCDEF";
- string?s[25];
- map<string,char>?m;
- struct?cj
- {?
- ????int?sum=0,xb;
- }b[256];
- bool?cmp(cj?x,cj?y)
- {
- ????return?x.sum>y.sum||(x.sum==y.sum&&x.xb<y.xb);
- }
- int?change1(char?x,char?y)
- {
- ????int?ans=0;
- ????if(x>='0'&&x<='9')
- ????????ans+=(x-'0')*16;
- ????else
- ????????ans+=(x-'A'+10)*16;
- ????if(y>='0'&&y<='9')
- ????????ans+=y-'0';
- ????else
- ????????ans+=y-'A'+10;
- ????return?ans;
- }
- string?change2(int?x)
- {
- ????string?ans="";
- ????ans+=a[x/16];
- ????ans+=a[x%16];
- ????return?ans;
- }
- int?main()
- {
- ????cin>>n;
- ????for(int?i=1;i<=n;i++)
- ????{
- ????????cin>>s[i];
- ????????int?len=s[i].size();
- ????????char?a1,a2;
- ????????for(int?j=0;j<len;j+=2)
- ????????{
- ????????????a1=s[i][j];a2=s[i][j+1];
- ????????????b[change1(a1,a2)].sum++;
- ????????????b[change1(a1,a2)].xb=change1(a1,a2);
- ????????}
- ????}
- ????sort(b,b+256,cmp);
- ????for(int?i=0;i<16;i++)
- ????{
- ????????cout<<change2(b[i].xb);
- ????????m[change2(b[i].xb)]=a[i];
- ????//????cout<<m[change2(b[i].xb)]<<endl;
- ????}
- ????cout<<endl;
- ????for(int?i=16;i<256;i++)
- ????{
- ????????int?min=0;
- ????????string?s2=change2(b[i].xb);
- ????????//cout<<s2<<'?';
- ????????for(int?j=1;j<16;j++)
- ????????{
- ????????????if(abs(b[j].xb-b[i].xb)<abs(b[min].xb-b[i].xb)||(abs(b[j].xb-(b[i].xb))==abs(b[min].xb-b[i].xb)&&i<min))
- ????????????????min=j;
- ????????//????cout<<abs(a[j]-b[i].sum)<<'?';
- ????????}
- ????????//cout<<min<<'?';
- ????????m[s2]=a[min];
- ????????//cout<<m[s2]<<endl;
- ????}
- ????
- ????for(int?i=1;i<=n;i++)
- ????{
- ????????int?len=s[i].size();
- ????????char?a1,a2;
- ????????for(int?j=0;j<len;j+=2)
- ????????{
- ????????????a1=s[i][j];a2=s[i][j+1];
- ????????????string?s2="";
- ????????????s2+=a1;
- ????????????s2+=a2;
- ????????????cout<<m[s2];
- ????????}
- ????????cout<<endl;
- ????}
- ????return?0;
- }
- /*
- 10
- 00FFCFAB00FFAC09071B5CCFAB76
- 00AFCBAB11FFAB09981D34CFAF56
- 01BFCEAB00FFAC0907F25FCFBA65
- 10FBCBAB11FFAB09981DF4CFCA67
- 00FFCBFB00FFAC0907A25CCFFC76
- 00FFCBAB1CFFCB09FC1AC4CFCF67
- 01FCCBAB00FFAC0F071A54CFBA65
- 10EFCBAB11FFAB09981B34CFCF67
- 01FFCBAB00FFAC0F071054CFAC76
- 1000CBAB11FFAB0A981B84CFCF66
- */
標(biāo)簽: