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. flutter button

    flutter button button类型: RaisedButton : 凸起的按钮,其实就是Android中的Material Design风格的Button ,继承自MaterialButt ...

  2. 阶段3 2.Spring_06.Spring的新注解_1 spring的新注解-Configuration和ComponentScan

    解决测试类重复代码的问题,xml还是存在的问题,没法脱离xml文件 要想在QueryRunner上加注解,是加不了的 创建工程 复制依赖项到pom.xml 复制注解的工程里面的com文件夹 配置文件b ...

  3. 阶段3 2.Spring_02.程序间耦合_8 工厂模式解耦的升级版

    遍历枚举 改造获取的方法,这样获取的对象就是单例模式 再次运行测试程序 对象只有一个实例的情况下对i这个值进行了反复的操作.当多个人活着多线程在使用时.这就会出现类成员变量由于第一个人的修改.后面看到 ...

  4. maven将自己的springboot项目打包成jar包后,作为工具包引入其他项目,找不到jar中的类

    将springboot项目打包成jar包,作为工具包导入项目后,找不到jar中的类. 原因是:springboot项目使用了自动的打包插件. 原先的插件配置: <build> <pl ...

  5. 在Linux命令行模式安装VMware Tools

    在Linux命令行模式安装VMware Tools 方法/步骤1: 首先启动CentOS 7,在VMware中点击上方“VM”,点击“Install VMware Tools...”(如已安装则显示“ ...

  6. CSP 之dvwa

    csp的本质是白名单,明确告诉浏览器哪些外部资源可以使用   请求头:[][x] Content-Security-Policy: script-src 'self'; object-src 'non ...

  7. AJAX得基本使用

    直接上案例:

  8. linux是什么与如何学习(三)

     1.1Linux是什么 Linux是在计算机上面运作的,所以说是一组软件. 1.2 Linux是什么?操作系统还是应用程序? 计算机主机是由一套硬件所组成的,为了有效的控制这些硬件资源,于是就有了操 ...

  9. python 并发编程 基于线程池实现并发的套接字通信

    不应该让服务端随着 并发的客户端数量增多,而无数起线程,应该用线程池,限制线程数量,控制最大并发数 io密集型程序,最大并发数是2 客户端 from socket import * client = ...

  10. XSS跨站简析

    XSS跨站脚本原理 当应用程序发送给浏览器的页面中包含用户提交的数据,但没有经过适当验证或转义时,就会导致跨站脚本漏洞 这个“跨”实际上属于浏览器的特性,而不是缺陷 (参考:浏览器同源策略) 不去直接 ...