【并查集】Wireless Network

传送门

An earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical team) have set up a wireless network with the lap computers, but an unexpected aftershock attacked, all computers in the network were all broken. The computers are repaired one by one, and the network gradually began to work again. Because of the hardware restricts, each computer can only directly communicate with the computers that are not farther than d meters from it. But every computer can be regarded as the intermediary of the communication between two other computers, that is to say computer A and computer B can communicate if computer A and computer B can communicate directly or there is a computer C that can communicate with both A and B.

In the process of repairing the network, workers can take two kinds of operations at every moment, repairing a computer, or testing if two computers can communicate. Your job is to answer all the testing operations.

继续阅读【并查集】Wireless Network

Transform

传送门:Transform

题意:

题意:t 组数据,每组给出 n 个数与 m 组询问,每组询问有 s、t 两个数,对于数 s 现给出两种变换,一种是改变 s 二进制位的某一位,即 0 变 1 或 1 变 0,另一种是让 s 从给出 n 个数当中的任意一个做异或运算,问从 s 到 t 最少要经过几步变换,最后输出每组的组号 i 与该组答案 zi 的和(模 1E9+7) 继续阅读Transform

字典树模板

#include<stdio.h>
#include<string.h>
#include<iostream>
#include<math.h>
#include<sstream>
#include<set>
#include<queue>
#include<map>
#include<vector>
#include<algorithm>
#include<limits.h>
#define inf 0x7fffffff
#define INFL 0x7fffffffffffffff
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define ULL unsigned long long
using namespace std;

typedef struct Trie{
    int v;
    Trie *next[26];
}Trie;
Trie root;
void createTrie(char *str)
{
    int len = strlen(str);
    Trie *p = &root, *q;
    for(int i=0; i<len; ++i)
    {
        int id = str[i]-'a';
        if(p->next[id] == NULL)
        {
            q = (Trie *)malloc(sizeof(root));
            q->v = 1;
            for(int j=0; j<26; ++j)
                q->next[j] = NULL;
            p->next[id] = q;
            p = p->next[id];
        }
        else
        {
            p->next[id]->v++;
            p = p->next[id];
        }
    }
}

int findTrie(char *str)
{
    int len = strlen(str);
    Trie *p = &root;
    for(int i=0; i<len; ++i)
    {
        int id = str[i]-'a';
        p = p->next[id];
        if(p == NULL)
            return 0;
    }
    return p->v;
}
void dele(char *str,int n)
{
    Trie *p = &root;
    int len = strlen(str);
    for(int i=0; i<len; ++i)
    {
        int id = str[i]-'a';
        p = p->next[id];
        p->v-=n;
    }
    for(int j=0; j<26; ++j)
    {
         p->next[j] = NULL;
    }
}
int main()
{
    int t;
    char s1[10000],s2[10000];
    for(int i=0;i<26;i++)
    {
        root.next[i]=NULL;
    }
    cin>>t;
    while(t--)
    {
        scanf("%s%s",s1,s2);
        if(s1[0]=='i')
        {
            createTrie(s2);
        }
        else if(s1[0]=='s')
        {
            int ans=findTrie(s2);
            if(ans)
            {
                puts("Yes");
            }
            else
            {
                puts("No");
            }
        }
        else
        {
            int cnt=findTrie(s2);
            if(cnt)
            {
                dele(s2,cnt);
            }
        }
    }
    return 0;
}