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大法好! */ /************************************** ...
随机推荐
- 2018-2019-2 20165235《网络对抗技术》Exp7 网络欺诈防范
2018-2019-2 20165235<网络对抗技术>Exp7 网络欺诈防范 实验目的 本实践的目标理解常用网络欺诈背后的原理,以提高防范意识,并提出具体防范方法 实验内容 (1)简单应 ...
- MVC的一个简单实例
基本思路: 一个Regist.jsp注册页面,用于收集用户信息,发送请求给控制器Servlet:控制器层Servlet封装模型层对象 jBean,并调用其方法regiser实现用户信息的保存:模型层J ...
- 《ECMAScript6 入门》
NVM Babel babel-core:提供 Babel 的 API,可以获得转码后的代码和抽象语法树. babel-polyfill:Babel 只能转换语法,如果想用类似 Promise.Gen ...
- maven setting.xml文件配置详情
1 首先,setting.xml一般存在与两个地方:maven的安装目录/conf/,和${user.home}/.m2/下.他们的区别是在maven安装目录下的setting.xml是所有用户都可以 ...
- http层负载均衡之 haproxy实践篇
方案 上篇文章讲到了负载均衡的相关理论知识,这篇文章我打算讲讲实践方法以及实践中遇到的问题 方案:haproxy http层负载均衡 安装一个haproxy服务,两个web服务 haproxy:192 ...
- Shadow安装
1.Shadow插件的安装 http://shadow.github.io/ 这是shadow主页的网址,Shadow是一个开源的网络模拟器/仿真器,我们用它模拟Tor网络的运行状况. 1.1安装 ...
- c++ 读取 utf-8 文件到 string
#include <iostream> #include <assert.h> #include <fstream> #include <string> ...
- 【EW系列】SAP EWM模块-EWM的常用T-CODE整理
公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[EWM系列]SAP EWM模块-EWM的常用T ...
- [Web 前端] 027 jQuery 相关尺寸与事件绑定
1. 相关尺寸 1.1 获取元素相对于文档的偏移量 var pos = $('#small').offset(); console.log(pos.left, pos.top); 1.2 获取当前元素 ...
- Mybatis—动态sql拼接问题
背景:使用Mybatis的最近半年,经常发现一些小坑,现在总结回顾下,记个小本本,不让它再来欺负我! 百度了许久,才留心到官网文档,比我的全,我很菜的! *************<if> ...