A

/* Huyyt */
#include <bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
#define mkp(a,b) make_pair(a,b)
#define pb push_back
using namespace std;
typedef long long ll;
const long long mod = 1e9 + ;
const int N = 2e5 + ;
int main()
{
ll n;
cin >> n;
if (n == )
{
cout << << endl;
return ;
}
n++;
if (n % == )
{
cout << n / << endl;
}
else
{
cout << n << endl;
}
}

B

/* Huyyt */
#include <bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
#define mkp(a,b) make_pair(a,b)
#define pb push_back
using namespace std;
typedef long long ll;
const long long mod = 1e9 + ;
const int N = 2e5 + ;
string a, b, c;
string str[];
int num[][];
int ansermaxn[];
int main()
{
ll n;
cin >> n;
for (int i = ; i <= ; i++)
{
cin >> str[i];
}
int aim = ;
int ansermax = -;
int ansnow;
for (int i = ; i <= ; i++)
{
for (int j = ; j < str[i].size(); j++)
{
num[i][str[i][j]]++;
}
}
for (int i = ; i <= ; i++)
{
for (int j = ; j <= ; j++)
{
if (num[i][j] + n <= str[i].size())
{
ansnow = num[i][j] + n; if (ansnow > ansermax)
{
aim = i;
ansermax = ansnow;
}
}
else
{
if (num[i][j] == str[i].size())
{
if (n == )
{
ansnow = str[i].size() - ;
}
else
{
ansnow = str[i].size();
}
}
else
{
ansnow = str[i].size();
}
if (ansnow > ansermax)
{
aim = i;
ansermax = ansnow;
}
}
ansermaxn[i] = max(ansermaxn[i], ansnow);
}
}
int cnt = ;
for (int i = ; i <= ; i++)
{
//cout << ansermaxn[i] << endl;
if (ansermaxn[i] == ansermax)
{
cnt++;
}
}
if (cnt > )
{
cout << "Draw" << endl;
return ;
}
if (aim == )
{
cout << "Kuro" << endl;
}
else if (aim == )
{
cout << "Shiro" << endl;
}
else
{
cout << "Katie" << endl;
}
}

C

/* Huyyt */
#include <bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
#define mkp(a,b) make_pair(a,b)
#define pb push_back
using namespace std;
typedef long long ll;
const long long mod = 1e9 + ;
const int N = 3e5 + ;
vector<int> gra[N];
ll anser = ;
ll reduce = ;
ll number1 = ;
ll number2 = ;
ll number = ;
int flag = ;
void dfs(int x, int pre, int aim, int flag)
{
if (flag)
{
number++;
}
int len = gra[x].size();
for (int i = ; i < len; i++)
{
int to = gra[x][i];
if (to == pre)
{
continue;
}
if (to == aim)
{
dfs(to, x, aim, );
}
else
{
dfs(to, x, aim, flag);
}
}
}
int main()
{
int n;
cin >> n;
int x, y;
int u, v;
cin >> x >> y;
for (int i = ; i <= n - ; i++)
{
scanf("%d %d", &u, &v);
gra[u].pb(v);
gra[v].pb(u);
}
anser = 1LL * (n - ) * n;
dfs(x, -, y, );
number1 = number;
number = ;
dfs(y, -, x, );
number2 = number;
anser -= 1LL * number2 * number1;
cout << anser << endl;
}

D

一开始给你一个空的集合

有两种操作:

①集合中加入一个数字X

②询问给你三个数字Xi Ki Si 查找集合中是否存在数字V满足 ① Ki是Xi和V的因子 ② V<=Si-Ki 当如果有多个满足条件的数输出Xi Xor V最大的那个V

解:

01字典树暴力操作

直接每次insert一个未出现过的数的时候 暴力Insert到每个它的因子里面去

复杂度为:1e5*ln(1e5)*位数(最多为18)=1e7

#include<bits/stdc++.h>
using namespace std;
const int maxn = ;
vector<int>G[maxn];
int vis[maxn];
void read(int &x)
{
x = ;
char c = getchar();
while (c > '' || c < '')
{
c = getchar();
}
while (c >= '' && c <= '')
{
x = (x << ) + (x << ) + c - '', c = getchar();
}
}
struct Trie //01字典树指针版
{
struct node
{
int Min, val;
node *ch[];
node()
{
Min = maxn; //维护一个最小值
ch[] = ch[] = NULL;
}
}*rt[maxn];
void init()
{
for (int i = ; i < maxn; i++)
for (int j = i; j < maxn; j += i) //复杂度1e5*ln1e5=1e6
{
G[j].push_back(i); //把一个数的因子全部push进去
}
for (int i = ; i < maxn; i++)
{
rt[i] = new node; //每个数赋予一个新指针
}
}
void insert(int x)
{
int Len = G[x].size(); //插入一个数
for (int i = ; i < Len; i++)
{
node *cur = rt[G[x][i]]; //暴力枚举insert到这个数的每个因子里面取
cur->Min = min(cur->Min, x); //维护最小值
for (int j = ; j >= ; j--) //争取取每位^1的使之异或值最大
{
if (cur->ch[x >> j & ] == NULL) //如果没有的话创造一个新节点
{
cur->ch[x >> j & ] = new node;
}
cur = cur->ch[x >> j & ];
cur->Min = min(cur->Min, x); //每个节点维护最小值
}
cur->val = x; //最后一个节点的值为x 最后取答案用
}
}
int query(int x, int k, int s)
{
if (x % k != ) //如果k是x和v的gcd的因子的话 x和v都是k的倍数
{
return -;
}
node *cur = rt[k]; //
if (cur->Min > s - x) //如果最小的都不能满足的话 不存在
{
return -;
}
for (int i = ; i >= ; i--)
{
int tb = x >> i & ;
if (cur->ch[tb ^ ] != NULL && cur->ch[tb ^ ]->Min <= s - x) //如果^1的值满足条件
{
cur = cur->ch[tb ^ ];
}
else
{
cur = cur->ch[tb];
}
}
return cur->val; //返回使之异或值最大的数列值
}
} T;
int main()
{
int N, i, j, opt, x, k, s;
T.init();
read(N);
while (N--)
{
read(opt);
if (opt == )
{
read(x);
if (!vis[x])
{
vis[x] = , T.insert(x);
}
}
else
{
read(x);
read(k);
read(s);
printf("%d\n", T.query(x, k, s));
}
}
return ;
}

Codeforces 979 字符串强制N变换最多出现字母 DFS子树 暴力01字典树的更多相关文章

  1. Codeforces 979 D. Kuro and GCD and XOR and SUM(异或和,01字典树)

    Codeforces 979 D. Kuro and GCD and XOR and SUM 题目大意:有两种操作:①给一个数v,加入数组a中②给出三个数x,k,s:从当前数组a中找出一个数u满足 u ...

  2. python 找出字符串中出现次数最多的字母

    # 请大家找出s=”aabbccddxxxxffff”中 出现次数最多的字母 # 第一种方法,字典方式: s="aabbccddxxxxffff" count ={} for i ...

  3. Codeforces Round #367 (Div. 2)---水题 | dp | 01字典树

    A.Beru-taxi 水题:有一个人站在(sx,sy)的位置,有n辆出租车,正向这个人匀速赶来,每个出租车的位置是(xi, yi) 速度是 Vi;求人最少需要等的时间: 单间循环即可: #inclu ...

  4. codeforces 842 D. Vitya and Strange Lesson(01字典树+思维+贪心)

    题目链接:http://codeforces.com/contest/842/problem/D 题解:像这种求一段异或什么的都可以考虑用字典树而且mex显然可以利用贪心+01字典树,和线段树差不多就 ...

  5. Codeforces Round #367 (Div. 2) D. Vasiliy's Multiset(01字典树求最大异或值)

    http://codeforces.com/contest/706/problem/D 题意:有多种操作,操作1为在字典中加入x这个数,操作2为从字典中删除x这个数,操作3为从字典中找出一个数使得与给 ...

  6. Vasiliy's Multiset CodeForces -706D || 01字典树模板

    就是一个模板 注意这题有一个要求:有一个额外的0一直保持在集合中 #include<cstdio> #include<algorithm> using namespace st ...

  7. Choosing The Commander CodeForces - 817E (01字典树+思维)

    As you might remember from the previous round, Vova is currently playing a strategic game known as R ...

  8. Codeforces 948D Perfect Security 【01字典树】

    <题目链接> 题目大意: 给定两个长度为n的序列,可以改变第二个序列中数的顺序,使得两个序列相同位置的数异或之后得到的新序列的字典序最小. 解题分析: 用01字典树来解决异或最值问题.因为 ...

  9. 数据结构&字符串:01字典树

    利用01字典树查询最大异或值 01字典树的是只含有0和1两种字符的字典树,在使用它的时候,把若干数字转成二进制后插入其中 在查询树中的哪个数字和给定数字有最大异或值的时候,从根开始贪心查询就ok了 H ...

随机推荐

  1. CSS样式属性单词之Left

    通常left单独在CSS中设置无效,需要在使用position属性下使用才能生效起作用.left左靠多少距离(距离左边多少)的作用. left 一.left认识与语法 left翻译:左边,左 在CSS ...

  2. C# 获取当前活动网络连接mac地址

    IPAddress localIp = null; IPAddress[] ipArray; ipArray = Dns.GetHostAddresses(Dns.GetHostName()); lo ...

  3. 不错的点击li标签删除的例子

    <script type="text/javascript">function delElement(obj){ obj.parentNode.removeChild( ...

  4. 用edoc2实现上传和下载

    import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import org.apache.http.Htt ...

  5. Java实验报告四

    一.实验目的 (1)掌握类的继承方法: (2)变量的继承和覆盖,方法的继承.重载和覆盖实现: 二.实验内容 1)实验代码 import java.util.Scanner; public class ...

  6. CentOS 上面 恢复 Oracle 数据库实例的简单操作流程

    1. 当获取了数据库的备份可以进行 oracle数据库的备份恢复操作 linux上面要复杂一些. 这里面简单描述一下. 2. 远程连接 linux 主要工具可以选择 xshell 如图示: 3. 建议 ...

  7. IOMETER的简单使用

    1. 网上下载文件: 一般至少包含两个: 2. 使用IOmeter 进行 功能测试. 注意选择 测试需要的盘 注意 选择的磁盘 会被充满. 会产生一个特别大的文件 3. 选择测试对象 4. 可以查看实 ...

  8. 极*Java速成教程 - (1)

    序言 众所周知,程序员需要快速学习新知识,所以就有了<21天精通C++>和<MySQL-从删库到跑路>这样的书籍,Java作为更"高级"的语言也不应该落后, ...

  9. Windown Server 2008配置tomcat9虚拟路径

    一.用途 用于保存项目运产生的文件 二.步骤 1.修改conf\下的web.xml <!-- 找到listings将false改为true -->        <init-para ...

  10. 死磕并发之CountDownLatch解析

    CountDownLatch解析 CountDownLatch是什么 CountDownLatch是基于AQS的阻塞工具,阻塞一个或者多个线程,直到所有的线程都执行完成. CountDownLatch ...