Codeforces 959 树构造 暴力求最小字典序互质序列
A
B
C
题目给你一个结论 最少需要min((odd,even)个结点可以把一棵树的全部边连起来 要求你输出两颗树
一棵树结论是正确的 另外一棵结论是正确的 正确结论的树很好造 主要是错误的树
题目给了你提示 提供了一个八个结点的错误的树 然后我们慢慢推发现只要N>=6就存在错误的树(把提供的树的左边两个结点删掉)
结点大于6就全部放在4号结点下
#include <bits/stdc++.h>
#define PI acos(-1.0)
#define mem(a,b) memset((a),b,sizeof(a))
#define TS printf("!!!\n")
#define pb push_back
#define inf 1e9
//std::ios::sync_with_stdio(false);
using namespace std;
//priority_queue<int,vector<int>,greater<int>> que; get min
const double eps = 1.0e-10;
const double EPS = 1.0e-4;
typedef pair<int, int> pairint;
typedef long long ll;
typedef unsigned long long ull;
//const int maxn = 3e5 + 10;
const int turn[][] = {{, }, { -, }, {, }, {, -}};
//priority_queue<int, vector<int>, less<int>> que;
//next_permutation
map<string, ll> mp;
string str[];
queue<int> que;
int main()
{
int n;
cin >> n;
if (n < )
{
cout << - << endl;
}
else
{
if (n % )
{
cout << << " " << << endl;
cout << << " " << << endl;
cout << << " " << << endl;
cout << << " " << << endl;
cout << << " " << << endl;
cout << << " " << n << endl;
for (int i = ; i <= n - ; i++)
{
if (i % )
{
cout << << " " << i << endl;
}
else
{
cout << << " " << i << endl;
}
}
}
else
{
cout << << " " << << endl;
cout << << " " << << endl;
cout << << " " << << endl;
cout << << " " << << endl;
cout << << " " << << endl;
for (int i = ; i <= n; i++)
{
if (i % )
{
cout << << " " << i << endl;
}
else
{
cout << << " " << i << endl;
}
}
}
}
for (int i = ; i <= n - ; i++)
{
cout << i << " " << i + << endl;
}
}
D
玄学暴力题
给你一个数列 要求你给出字典序最小的但不小于给定数列的目标数列 要求目标数列内两两互质
假设我们要求出这个数列可能要求的最大的数 质数的数量级是x/logx 所以 x/logx-1e4>1e5 大概可以求出x在2e6差不多
然后把2-2e6的每个数都存到一个set里面这个set存的是当前所有可插入原数组的数 同时把每个数的质因数都存到一个vector里面
然后输入原有的数组 每次输入一个数就在set里去除掉他的质因数的倍数(包括它本身) 这样这个set里面的每个数就都是当前合法插入数
如果需要插入的数比原数列的大 就可以直接输出set.begin()
#include <bits/stdc++.h>
#define PI acos(-1.0)
#define mem(a,b) memset((a),b,sizeof(a))
#define TS printf("!!!\n")
#define pb push_back
#define inf 1e9
//std::ios::sync_with_stdio(false);
using namespace std;
//priority_queue<int,vector<int>,greater<int>> que; get min
const double eps = 1.0e-10;
const double EPS = 1.0e-4;
typedef pair<int, int> pairint;
typedef long long ll;
typedef unsigned long long ull;
//const int maxn = 3e5 + 10;
const int turn[][] = {{, }, { -, }, {, }, {, -}};
//priority_queue<int, vector<int>, less<int>> que;
//next_permutation
bool prime[];
vector<int> beishu[];
bool eras[];
set<int> num;
bool pre = true;
int main()
{
int n;
cin >> n;
for (int i = ; i <= ; i++)
{
num.insert(i);
if (prime[i])
{
continue;
}
//cout<<i<<endl;
for (int j = i; j <= ; j += i)
{
prime[j] = true;
beishu[j].pb(i);
}
}
//TS;
int now;
int aim;
for (int i = ; i <= n; i++)
{
scanf("%d", &now);
if (pre)
{
aim = *num.lower_bound(now);
if (aim > now)
{
pre = false;
}
}
else
{
aim = *num.begin();
}
cout << aim << " ";
for (int j : beishu[aim])
{
for (int k = j; k < ; k += j)
{
if (!eras[k])
{
num.erase(k);
eras[k] = true;
}
}
}
}
return ;
}
E
找规律或者OEIS
#include <bits/stdc++.h>
#define PI acos(-1.0)
#define mem(a,b) memset((a),b,sizeof(a))
#define TS printf("!!!\n")
#define pb push_back
#define inf 1e9
//std::ios::sync_with_stdio(false);
using namespace std;
//priority_queue<int,vector<int>,greater<int>> que; get min
const double eps = 1.0e-10;
const double EPS = 1.0e-4;
typedef pair<int, int> pairint;
typedef long long ll;
typedef unsigned long long ull;
//const int maxn = 3e5 + 10;
const int turn[][] = {{, }, { -, }, {, }, {, -}};
//priority_queue<int, vector<int>, less<int>> que;
//next_permutation
ll dp[];
ll dfs(ll x)
{
if (x <= )
{
return dp[x];
}
if (x % )
{
return 2LL * dfs(x / ) + x / + ;
}
else
{
return 2LL * dfs(x / ) + x / ;
}
}
int main()
{
ll n;
cin >> n;
ll anser;
dp[] = ;
for (int i = ; i <= ; i++)
{
dp[i * ] = * dp[i] + i;
dp[i * + ] = * dp[i] + i + ;
}
//cout << dp[n - 1] << endl;
// for(int i=1;i<=10;i++)
// cout<<dp[i]<<endl;
cout << dfs(n - ) << endl;
return ;
}
Codeforces 959 树构造 暴力求最小字典序互质序列的更多相关文章
- HDU1814(Peaceful Commission) 【2-SAT DFS暴力求最小字典序的模板】
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1814 题意:给出一个数n,代表有n个党派,每个党派要求派出其中一个人去参加会议,且只能派出一人.给出m ...
- Subordinates CodeForces - 737C (树,构造)
大意: 求构造一棵树, 每个节点回答它的祖先个数, 求最少打错次数. 挺简单的一个构造, 祖先个数等价于节点深度, 所以只需要确定一个最大深度然后贪心即可. 需要特判一下根的深度, 再特判一下只有一个 ...
- New Roads CodeForces - 746G (树,构造)
大意:构造n结点树, 高度$i$的结点有$a_i$个, 且叶子有k个. 先确定主链, 然后贪心放其余节点. #include <iostream> #include <algorit ...
- poj1509(环形字符串求最小字典序)
题意:给你一串字符串,但是这串字符串是环形的,让你找个位置切开,使得它的字典序最小....... 思路:典型的最小表示法....... #include<iostream> #includ ...
- BZOJ4974(给Next求最小字典序原串)
输入给出了最小循环节长度,暗示next数组. 然后自己按照自己的kmp板子逆着来一遍就好. ; int n, a, Next[maxn]; char str[maxn]; ]; int main() ...
- 【bzoj4921】[Lydsy六月月赛]互质序列 暴力
题目描述 给出一个序列,要求删除一段非空区间,使得剩下的数的个数大于等于2.求所有删除方式剩下的数的最大公约数的和. 输入 第一行包含一个正整数n(3<=n<=100000),表示序列的长 ...
- 【2-SAT(最小字典序/暴力染色)】HDU1814-Peaceful Commission
[题目大意] 和平委员会每个党派有2个人,只能派出其中1个,其中有一些人之间互相讨厌不能同时派出.求出派遣方案,如果有多种方案输出字典序最小的方案. [思路] 最小字典序只能用暴力染色.初始时均没有染 ...
- HDU - 5324:Boring Class (CDQ分治&树状数组&最小字典序)
题意:给定N个组合,每个组合有a和b,现在求最长序列,满足a不升,b不降. 思路:三位偏序,CDQ分治. 但是没想到怎么输出最小字典序,我好菜啊. 最小字典序: 我们倒序CDQ分治,ans[i]表 ...
- 构造+暴力 Codeforces Round #283 (Div. 2) B. Secret Combination
题目传送门 /* 构造+暴力:按照题目意思,只要10次加1就变回原来的数字,暴力枚举所有数字,string大法好! */ /************************************** ...
随机推荐
- 图的普里姆(Prim)算法求最小生成树
关于图的最小生成树算法------普里姆算法 首先我们先初始化一张图: 设置两个数据结构来分别代表我们需要存储的数据: lowcost[i]:表示以i为终点的边的最小权值,当lowcost[i]=0说 ...
- 分布式工作流任务调度系统Easy Scheduler正式开源
分布式工作流任务调度系统Easy Scheduler正式开源 1.背景 在多位技术小伙伴的努力下,经过近2年的研发迭代.内部业务剥离及重构,也经历一批种子用户试用一段时间后,EasyScheduler ...
- Python深度学习读书笔记-3.神经网络的数据表示
标量(0D 张量) 仅包含一个数字的张量叫作标量(scalar,也叫标量张量.零维张量.0D 张量).在Numpy 中,一个float32 或float64 的数字就是一个标量张量(或标量数组).你可 ...
- Vue知识整理13:表单输入绑定(v-model)
text:将输入框等表单,通过data变量实现数据绑定. textbox:数据绑定 3.checkbox和redio组件: 注意:data数据变量中,checkbox有可能会有多个结果,所以用数组: ...
- 五:flask-url_for使用详解
from flask import url_for url_for(视图函数名):根据视图函数名指定url,只要视图函数不变,url随便变都不会影响 url_for源码: 示例视图,执行流程 带参数: ...
- Selenium学习之==>Css Selector使用方法
一.什么是Css Selector Css Selector定位实际就是HTML的Css选择器的标签定位 工具 Css Selector的练习建议大家安装火狐浏览器后,下载插件,FireFinder ...
- 那些堪称神器的 Chrome 插件
Chrome 的简洁快速以及丰富的插件种类使得它在国内日益盛行,帮助了我们很多 Chrome 用户提升了工作效率,而今天要给大家推荐8款实用甚至堪称神器的 Chrome 插件,希望对提升大家的工作效率 ...
- TCP的三次握手过程
TCP::传输控制协议(Transmission Control Protocol ) 是一种面相连接的.可靠的.基于字节流的 传输层通信协议. TCP是一种面相连接的协议.其显著的特点就是在 ...
- 使用Inception-v3进行图像分类
https://blog.csdn.net/sinat_27382047/article/details/80534234 https://www.jianshu.com/p/cc830a6ed54b ...
- supervisor启动elk7.4.0组件
es [program:elasticsearch] command = /srv/app/elk/elasticsearch/bin/elasticsearch autostart = true s ...