今天我在做题,发现了一个奇葩事:
这是我的代码:
#include <bits/stdc++.h>
#define rep(i,x,y) for (int i=x;i<=y;i++)
#define rrep(i,x,y) for (int i=y;i>=x;i--)
using namespace std;
namespace drest {
#define _fcfo friend const fast_io& operator
#define _io const fast_io& io
#define _gething1(_ch) (bool) ((_ch=getchar())==' '||_ch=='\n'||_ch=='\t'||_ch==4)
#define _gething2(_ch) (bool) ((_ch = getchar())<'0'||_ch>'9')
/* code by Drest */
const char* _website_ = "dresteam.online";
using std::string; using std::pair; using std::map; using std::set;
using std::vector; using std::queue; using std::deque; using std::priority_queue;
using std::sort; using std::swap; using std::min; using std::max;
using std::floor; using std::ceil; char _ch_;
template<class T> T abs(const T & x) {return x < 0 ? -x : x;}
class fast_io {
template<class T> static const fast_io& input_integer(_io, T &x) {
T f = 1, res; while(_gething2(_ch_)) if(_ch_ == '-') f = -1; res = _ch_ ^ 48;
while(!_gething2(_ch_)) res= (res << 1) + (res << 3) + (_ch_ ^ 48); x = res * f; return io;
}
template<class T> static const fast_io& output_integer(_io, T &x)
{if(x<0)putchar('-'); x = abs(x); if(x>9)io<<(T)(x/10); putchar(x%10+'0'); return io;}
_fcfo >> (_io, bool &x) {return input_integer(io, x);}
_fcfo >> (_io, short &x) {return input_integer(io, x);}
_fcfo >> (_io, int &x) {return input_integer(io, x);}
_fcfo >> (_io, long &x) {return input_integer(io, x);}
_fcfo >> (_io, long long &x) {return input_integer(io, x);}
_fcfo >> (_io, __int128 &x) {return input_integer(io, x);}
_fcfo << (_io, short x) {return output_integer(io, x);}
_fcfo << (_io, int x) {return output_integer(io, x);}
_fcfo << (_io, long x) {return output_integer(io, x);}
_fcfo << (_io, long long x) {return output_integer(io, x);}
_fcfo << (_io, __int128 x) {return output_integer(io, x);}
_fcfo >> (_io, float &x) {scanf("%f", &x); return io;}
_fcfo >> (_io, double &x) {scanf("%lf", &x); return io;}
_fcfo << (_io, float x) {printf("%f", x); return io;}
_fcfo << (_io, double x) {printf("%lf", x); return io;}
_fcfo >> (_io, char &x) {while(_gething1(x)){} return io;}
_fcfo << (_io, char x) {putchar(x); return io;}
_fcfo >> (_io, string &x) {while(_gething1(_ch_)){} x = _ch_; while(!_gething1(_ch_)) x += _ch_; return io;}
_fcfo << (_io, string x) {for(int i=0; i < x.size(); i++)putchar(x[i]); return io;}
_fcfo >> (_io, char* &x) {string res; io >> res; x=&res[0]; return io;}
_fcfo << (_io, char* x) {for (int i=0; i < strlen(x); i++) putchar(x[i]); return io;}
public:
fast_io& getline(string &x) {x = ""; while ((_ch_ = getchar()) != '\n' && _ch_ != 4) x += _ch_; return *this;}
fast_io& getline(char* &x) {string res; this->getline(res); x = &res[0]; return *this;}
};
fast_io io, cin, cout; const char & endl = '\n';
}
#define cin io
#define cout io
#define endl '\n'
using namespace drest;
string s;
map<char,int> st;
int maxn,sp;
char p,a[1001];
bool b[1001];
inline bool prime (int k)
{
if (k<2) return false;
for (int i=2;i*i<=k;i++)
if (k%i==0) return false;
return true;
}
int main ()
{
cin>>s;
rep (i,0,s.size ()-1) st[s[i]]++;
for (auto i:st)
if (maxn<i.second)
maxn=i.second,p=i.first;
rep (i,2,s.size ())
if (!prime (i)) b[i]=1,sp++;
else if (i<=s.size ()/2) b[i]=1,sp++;
if (maxn<sp) cout<<"NO\n",exit (0);
cout<<"YES\n",st[p]-=sp;
rep (i,1,s.size ())
if (b[i]) a[i]=p;
int w=1;
for (auto i:st)
rep (j,1,i.second)
{
while (a[w++]==p) ;
a[w++]=i.first;
}
rep (i,1,s.size ()) cout<<a[i];
return 0;
}
这是标程的代码:
#include <bits/stdc++.h>
#define rep(i,x,y) for (int i=x;i<=y;i++)
#define rrep(i,x,y) for (int i=y;i>=x;i--)
using namespace std;
namespace drest {
#define _fcfo friend const fast_io& operator
#define _io const fast_io& io
#define _gething1(_ch) (bool) ((_ch=getchar())==' '||_ch=='\n'||_ch=='\t'||_ch==4)
#define _gething2(_ch) (bool) ((_ch = getchar())<'0'||_ch>'9')
/* code by Drest */
const char* _website_ = "dresteam.online";
using std::string; using std::pair; using std::map; using std::set;
using std::vector; using std::queue; using std::deque; using std::priority_queue;
using std::sort; using std::swap; using std::min; using std::max;
using std::floor; using std::ceil; char _ch_;
template<class T> T abs(const T & x) {return x < 0 ? -x : x;}
class fast_io {
template<class T> static const fast_io& input_integer(_io, T &x) {
T f = 1, res; while(_gething2(_ch_)) if(_ch_ == '-') f = -1; res = _ch_ ^ 48;
while(!_gething2(_ch_)) res= (res << 1) + (res << 3) + (_ch_ ^ 48); x = res * f; return io;
}
template<class T> static const fast_io& output_integer(_io, T &x)
{if(x<0)putchar('-'); x = abs(x); if(x>9)io<<(T)(x/10); putchar(x%10+'0'); return io;}
_fcfo >> (_io, bool &x) {return input_integer(io, x);}
_fcfo >> (_io, short &x) {return input_integer(io, x);}
_fcfo >> (_io, int &x) {return input_integer(io, x);}
_fcfo >> (_io, long &x) {return input_integer(io, x);}
_fcfo >> (_io, long long &x) {return input_integer(io, x);}
_fcfo >> (_io, __int128 &x) {return input_integer(io, x);}
_fcfo << (_io, short x) {return output_integer(io, x);}
_fcfo << (_io, int x) {return output_integer(io, x);}
_fcfo << (_io, long x) {return output_integer(io, x);}
_fcfo << (_io, long long x) {return output_integer(io, x);}
_fcfo << (_io, __int128 x) {return output_integer(io, x);}
_fcfo >> (_io, float &x) {scanf("%f", &x); return io;}
_fcfo >> (_io, double &x) {scanf("%lf", &x); return io;}
_fcfo << (_io, float x) {printf("%f", x); return io;}
_fcfo << (_io, double x) {printf("%lf", x); return io;}
_fcfo >> (_io, char &x) {while(_gething1(x)){} return io;}
_fcfo << (_io, char x) {putchar(x); return io;}
_fcfo >> (_io, string &x) {while(_gething1(_ch_)){} x = _ch_; while(!_gething1(_ch_)) x += _ch_; return io;}
_fcfo << (_io, string x) {for(int i=0; i < x.size(); i++)putchar(x[i]); return io;}
_fcfo >> (_io, char* &x) {string res; io >> res; x=&res[0]; return io;}
_fcfo << (_io, char* x) {for (int i=0; i < strlen(x); i++) putchar(x[i]); return io;}
public:
fast_io& getline(string &x) {x = ""; while ((_ch_ = getchar()) != '\n' && _ch_ != 4) x += _ch_; return *this;}
fast_io& getline(char* &x) {string res; this->getline(res); x = &res[0]; return *this;}
};
fast_io io, cin, cout; const char & endl = '\n';
}
#define cin io
#define cout io
#define endl '\n'
using namespace drest;
string s;
map<char,int> st;
int maxn,sp;
char p,a[1001];
bool b[1001];
inline bool prime (int k)
{
if (k<2) return false;
for (int i=2;i*i<=k;i++)
if (k%i==0) return false;
return true;
}
int main ()
{
cin>>s;
rep (i,0,s.size ()-1) st[s[i]]++;
for (auto i:st)
if (maxn<i.second)
maxn=i.second,p=i.first;
rep (i,2,s.size ())
if (!prime (i)) b[i]=1,sp++;
else if (i<=s.size ()/2) b[i]=1,sp++;
if (maxn<sp) cout<<"NO\n",exit (0);
cout<<"YES\n",st[p]-=sp;
rep (i,1,s.size ())
if (b[i]) a[i]=p;
int w=1;
for (auto i:st)
rep (j,1,i.second)
{
while (a[w]==p) w++;
a[w++]=i.first;
}
rep (i,1,s.size ()) cout<<a[i];
return 0;
}
感觉都一样啊,为啥结果不一样?