CSP-S允许使用随机数吗?
  • 板块学术版
  • 楼主Specter_LiZN
  • 当前回复4
  • 已保存回复4
  • 发布时间2024/10/25 10:51
  • 上次更新2024/10/25 13:34:01
查看原帖
CSP-S允许使用随机数吗?
465029
Specter_LiZN楼主2024/10/25 10:51

如题,原来写字符串哈希的时候用了srand()
不知道CCF的评测机 允不允许用/能不能实现

#include <bits/stdc++.h>
#define f(i,a,b) for(int i=a;i<=b;i++)
#define Shion cout <<'\n'<<"Shion is too poor to print that."
const signed Miku=0x3f3f3f3f;
const signed N=1e4+50;
using namespace std;
#define ull unsigned long long
int n,ans=1;
string in;
int mod1=1e9+7,mod2=1e9+9,base;
struct saving{
  ull a,b;
}sav[10010];
ull hashCalc(string s,bool op){
  int len=s.length();
  ull ans=0;
  f(i,0,len-1)
    if(op)
      ans=(ans*base+s[i])%mod1;
    else
      ans=(ans*base+s[i])%mod2;
  return ans;
}
bool cmp(saving a,saving b){
  return a.a<b.a;
}
signed main(){
  ios::sync_with_stdio(0),cin.tie(0);
  srand(time(0));
  base=rand()%200+50;
  mod1+=rand()%50;
  mod2+=rand()%50;
  cin>>n;
  f(i,1,n){
    cin>>in;
    sav[i].a=hashCalc(in,0);
    sav[i].b=hashCalc(in,1);
  }
  sort(sav+1,sav+n+1,cmp);
  f(i,2,n)
    if(sav[i].a!=sav[i-1].a&&sav[i].b!=sav[i-1].b)
      ans++;
  cout<<ans;
  return 0;
  Shion;
}
2024/10/25 10:51
加载中...