头像

暴怒的死肥宅




离线:1小时前



暴怒的死肥宅
2020-06-23 23:33
//这里填你的代码^^
//注意代码要放在两组三个点之间,才可以正确显示代码高亮哦~

#include[HTML_REMOVED]
typedef long long ll;

using namespace std;

const int N = 100010, M = 3100010;

int tr[M][2],idx;
//int cnt[N];
int h[N],e[M],ne[M],c[M],cnt;
void add(int u,int v,int w)
{
e[cnt]=v;ne[cnt]=h[u];c[cnt]=w;h[u]=cnt;
}
void insert(int x)
{ int p=0;
for(int i=30;i>=0;i–)
{
int &s=tr[p][x>>i&1];
if(!s) s=
idx;
p=s;
}

    // 根据题目

}
int a[N];
void dfs(int u,int father,int sum)
{ a[u]=sum;
for(int i=h[u]; ~i;i=ne[i])
{
int j=e[i];
if(j!=father)
dfs(j,u,sum^c[i]);
}

}
int query(int x)
{
int p=0; ll res=0;
for(int i=30;i>=0;i–)
{
int s=x>>i[HTML_REMOVED]
if(tr[p][!s])
{
res+=1<<i; p=tr[p][!s];
}
else p=tr[p][s];
}
return res;
} int n;

int main()
{ cin>>n;
memset(h, -1, sizeof h);

for(int i=0;i[HTML_REMOVED]>u>>v>>w;
add(u,v,w);
add(v,u,w);
}dfs(0,-1,0);
int res=0;
for (int i = 0; i < n; i ++ ) insert(a[i]);

for(int i=0;i<n;i++)
{
res=max(res,query(a[i]));
} cout<<res<<endl;

 return 0;

}



活动打卡代码 AcWing 143. 最大异或对

暴怒的死肥宅
2020-06-23 23:32
//这里填你的代码^^
//注意代码要放在两组三个点之间,才可以正确显示代码高亮哦~

include[HTML_REMOVED]

typedef long long ll;

using namespace std;

const int N=100010+10;
const int M=3100010;
const int N = 100010, M = 3100010;

int tr[M][2],idx;
int cnt[N];

void insert(int x)
{
int p=0;
for(int i=30;~i;i– )
{
int &s=tr[p][x>>i&1];
if(!s) s=++idx;
p=s;

   }
    // 根据题目

}
int query(int x)
{
int p=0; ll res=0;
for(int i=30;~i;i–)
{
int s = x >> i & 1;
if(tr[p][!s])
{
res+=1<[HTML_REMOVED]>n;
for(int i=0;i[HTML_REMOVED]>a[i];insert(a[i]);
}
int res=0;
for(int i=0;i<n;i++)
{
res=max(res,query(a[i]));
} cout<<res<<endl;

 return 0;

}



活动打卡代码 AcWing 142. 前缀统计

暴怒的死肥宅
2020-06-23 23:32
//这里填你的代码^^
//注意代码要放在两组三个点之间,才可以正确显示代码高亮哦~

include[HTML_REMOVED]

using namespace std;

const int N=100000+3;
const int M=100000;

int tr[N][26],idx;
int cnt[N];
char str[M];
void insert( )
{
int p=0;
for(int i=0;str[i];i)
{
int &s=tr[p][str[i]-‘a’];
if(!s) s=
idx;
p=s;
}
cnt[p];
}
int query()
{
int p=0,res=0;
for(int i=0;str[i];i
)
{
int &s=tr[p][str[i]-‘a’];
if(!s) break;
p=s;
res+=cnt[p];
}
return res;
}
int main()
{
int n,m;
cin>>n>>m;
while(n–)
{
cin>>str;
insert();
}
while(m–)
{
cin>>str;
cout<<query()<<endl;

 }
 return 0;

}



活动打卡代码 AcWing 140. 后缀数组

暴怒的死肥宅
2020-06-23 23:31
//这里填你的代码^^   测试板子
//注意代码要放在两组三个点之间,才可以正确显示代码高亮哦~

include [HTML_REMOVED]

using namespace std;
typedef unsigned long long ull;
const int N=100005;
const int P=131;
int p[N];
ull h[N];
char str[N];
int sa[N],ht[N]; int n;

int get_hash(int l,int r){
return h[r]-h[l-1]*p[r-l+1];
}
int prefix(int a,int b)
{
int l=0,r=min(n-a+1,n-b+1);
while(l[HTML_REMOVED]>1;
if(get_hash(a,a+mid-1)!=get_hash(b,b+mid-1)) r=mid+1;
else l=mid;
}
return l;
}
int cmp(int a,int b)
{
int l=prefix(a,b);
int av=a+l>n? -INT_MIN:str[a+l];
int bv=b+l>n? -INT_MIN:str[b+l];
return av[HTML_REMOVED]>str;
n = strlen(str + 1);

p[0] = 1;
for (int i = 1; i <= n; i ++ )
{
    h[i] = h[i - 1] * P + str[i] - 'a' + 1;
    p[i] = p[i - 1] * P;
    sa[i] = i;
}

sort(sa + 1, sa + 1 + n, cmp);

for (int i = 1; i <= n; i ++ ) printf("%d ", sa[i] - 1);
puts("");
for (int i = 1; i <= n; i ++ )
    if (i == 1) printf("0 ");
    else printf("%d ", prefix(sa[i - 1], sa[i]));
puts("");


 return 0;

}




暴怒的死肥宅
2020-06-23 23:31
//这里填你的代码^^
//注意代码要放在两组三个点之间,才可以正确显示代码高亮哦~

include [HTML_REMOVED]

using namespace std;
const int maxn = 1000005;
char str[maxn];
char temp[maxn2];
int l[maxn
2];
int malache(char *str)
{
int len = strlen(str);//cout<<len<<” “;

for(int i = 0; i <=2*len ; i+=2)
{
     temp[i]='#';
     temp[i+1]=str[i/2];
} temp[2*len+1]='#';  
 //字符串结尾加一个字符,防止越界

// temp[2len+3]=0;
int mx = 0, po = 0,ans = 0;
for(int i = 0;i <=2
len; i++)
{
if(i [HTML_REMOVED] mx) {po = i; mx = l[i]+i;}
ans = max(ans , l[i]);
}
return ans-1;
}
int main()
{
int T = 1;

while(cin>>str)
{if (strcmp(str ,"END")==0) //结束读入
        return 0;
     memset(temp,0,sizeof(temp));

   int ans=malache(str);   printf("Case %d: %d\n",T++,ans);
}
return 0;

}




暴怒的死肥宅
2020-06-23 23:30
//这里填你的代码^^
//注意代码要放在两组三个点之间,才可以正确显示代码高亮哦~

#include [HTML_REMOVED]

const int N=1000005;
const int p=131;

define d(x,y) (x*n+y)

using namespace std;
int h[N];
int ph[N]; int n;
char str[N];
int get_hash( int l,int r)
{
return h[r]-h[l-1]*ph[r-l+1];
}

void init ()
{ ph[0]=1;
scanf(“%s”, str + 1);
int n=strlen(str+1);
for(int i=1;i<=n;i)
{ h[i]=h[i-1]p+str[i]-‘a’+1;
ph[i]=ph[i-1]
p;
}
}
int main()
{
init();
int m;
cin>>m;
for(int i=1;i<=m;i
)
{
int l1,r1,l2,r2; cin>>l1>>r1>>l2>>r2;
if(get_hash(l1,r1)==get_hash(l2,r2))
puts(“Yes”);

       else
       {
            puts("No");
       }

}

return 0;
}



活动打卡代码 AcWing 138. 兔子与兔子

暴怒的死肥宅
2020-06-23 23:30
//这里填你的代码^^
//注意代码要放在两组三个点之间,才可以正确显示代码高亮哦~

#include [HTML_REMOVED]

const int N=1000005;
const int p=131;

define d(x,y) (x*n+y)

using namespace std;
int h[N];
int ph[N]; int n;
char str[N];
int get_hash( int l,int r)
{
return h[r]-h[l-1]*ph[r-l+1];
}

void init ()
{ ph[0]=1;
scanf(“%s”, str + 1);
int n=strlen(str+1);
for(int i=1;i<=n;i)
{ h[i]=h[i-1]p+str[i]-‘a’+1;
ph[i]=ph[i-1]
p;
}
}
int main()
{
init();
int m;
cin>>m;
for(int i=1;i<=m;i
)
{
int l1,r1,l2,r2; cin>>l1>>r1>>l2>>r2;
if(get_hash(l1,r1)==get_hash(l2,r2))
puts(“Yes”);

       else
       {
            puts("No");
       }

}

return 0;
}



活动打卡代码 AcWing 97. 约数之和

暴怒的死肥宅
2019-06-21 08:40

include [HTML_REMOVED]

include [HTML_REMOVED]

include [HTML_REMOVED]

include [HTML_REMOVED]

include [HTML_REMOVED]

include [HTML_REMOVED]

include [HTML_REMOVED]

include [HTML_REMOVED]

include [HTML_REMOVED]

include [HTML_REMOVED]

include [HTML_REMOVED]

include [HTML_REMOVED]

include [HTML_REMOVED]

include [HTML_REMOVED]

include [HTML_REMOVED]

include[HTML_REMOVED]

include [HTML_REMOVED]

/*********/
using namespace std;

define ll long long

ll a,b;
ll mod=9901;

ll quickPower(ll a, ll b, int c)
{
if (b==0) return 1%c;

if (b==1)return a%c;
ll ans = 1;
while (b)
{

    if (b % 2 == 1)
        ans = (ans * a) % c;
    b /= 2;
    a = (a * a) % c;
}
return ans;

}

ll sumc(ll p,ll c)//(p1k1+p2^k2+.....
{
if (c==0)
return 1;
if(c&1)
return ((1+quickPower(p,(c+1)>>1,mod))
sumc(p,(c-1)>>1))%mod;//奇数的情况下
else
return ((1+quickPower(p,c>>1,mod))*sumc(p,(c>>1)-1)+quickPower(p,c,mod))%mod;//偶数的情况下
}
int main() {
cin>>a>>b;
ll ans=1;
for(int i=2;i<=a;i)
{
ll k=0;
while(a%i==0)
{
k
;
a/=i;
}

      ans=(ans*sumc(i,k*b))%mod;

}
if (!a) cout<<0<<endl;

else
cout<<ans<<endl;
return 0;

}



活动打卡代码 AcWing 96. 奇怪的汉诺塔

暴怒的死肥宅
2019-06-19 15:26

include [HTML_REMOVED]

using namespace std;
int a[7][7],b[7][7],n,answer;
int init()
{
getchar();
for (int i=1;i<=5;i)
{
for (int j=1;j<=5;j
)
{
char ch=getchar();
a[i][j]=ch-‘0’;
}
getchar();
}
}
int handle(int x,int y)
{
b[x][y]^=1;
b[x-1][y]^=1;
b[x][y+1]^=1;
b[x][y-1]^=1;
b[x+1][y]^=1;
}
bool judge(void)
{
for (int i=1;i<=5;i)
for (int j=1;j<=5;j
)
if(!b[i][j])
return false;
return true;
}
int work(void)
{
answer=1e7;
for (int i=1;i<=(1<<5);i)
{
int ans=0;
memcpy(b,a,sizeof(a));
for (int j=1;j<=5;j
)
if (i>>(j-1) & 1)
{
handle(1,j);
ans;
}
for (int j=1;j<=4;j
)
for (int k=1;k<=5;k)
if (!b[j][k])
{
ans
;
handle(j+1,k);
}
if (judge())
answer=min(ans,answer);
}
return answer;
}
int main()
{
cin>>n;
while(n–)
{
init();
if (work()<=6)
cout<<answer;
else
cout<<”-1”;
puts(“”);
}
return 0;
}




暴怒的死肥宅
2019-06-19 14:06

include[HTML_REMOVED]??

include[HTML_REMOVED]??

include[HTML_REMOVED]??

include[HTML_REMOVED]???

include[HTML_REMOVED]??

include[HTML_REMOVED]??

include[HTML_REMOVED]

include [HTML_REMOVED]

include [HTML_REMOVED]

define cl(a,b) memset(a,b,sizeof(a));

define maxn 200005

define inf ?0x3f3f3f3f;

define ll long long

define MOD 1000000007

using namespace std;
int n ; int ans[20],vis[30];

void dfs(int k)
{
if(k==n+1)
{

      for(int i=1;i<=n;i++)

      {
          cout<<ans[i]<<" ";
      }cout<<endl;

      return ;
  }


  for(int i=1;i<=n;i++)
  {
      if(!vis[i])
      {
          ans[k]=i;
          vis[i]=1;
          dfs(k+1);
          ans[k]=0;
          vis[i]=0;
      }
  }

}

int main()
{
cin>>n;
dfs(1);
return 0;

}