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 树构造 暴力求最小字典序互质序列的更多相关文章

  1. HDU1814(Peaceful Commission) 【2-SAT DFS暴力求最小字典序的模板】

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1814 题意:给出一个数n,代表有n个党派,每个党派要求派出其中一个人去参加会议,且只能派出一人.给出m ...

  2. Subordinates CodeForces - 737C (树,构造)

    大意: 求构造一棵树, 每个节点回答它的祖先个数, 求最少打错次数. 挺简单的一个构造, 祖先个数等价于节点深度, 所以只需要确定一个最大深度然后贪心即可. 需要特判一下根的深度, 再特判一下只有一个 ...

  3. New Roads CodeForces - 746G (树,构造)

    大意:构造n结点树, 高度$i$的结点有$a_i$个, 且叶子有k个. 先确定主链, 然后贪心放其余节点. #include <iostream> #include <algorit ...

  4. poj1509(环形字符串求最小字典序)

    题意:给你一串字符串,但是这串字符串是环形的,让你找个位置切开,使得它的字典序最小....... 思路:典型的最小表示法....... #include<iostream> #includ ...

  5. BZOJ4974(给Next求最小字典序原串)

    输入给出了最小循环节长度,暗示next数组. 然后自己按照自己的kmp板子逆着来一遍就好. ; int n, a, Next[maxn]; char str[maxn]; ]; int main() ...

  6. 【bzoj4921】[Lydsy六月月赛]互质序列 暴力

    题目描述 给出一个序列,要求删除一段非空区间,使得剩下的数的个数大于等于2.求所有删除方式剩下的数的最大公约数的和. 输入 第一行包含一个正整数n(3<=n<=100000),表示序列的长 ...

  7. 【2-SAT(最小字典序/暴力染色)】HDU1814-Peaceful Commission

    [题目大意] 和平委员会每个党派有2个人,只能派出其中1个,其中有一些人之间互相讨厌不能同时派出.求出派遣方案,如果有多种方案输出字典序最小的方案. [思路] 最小字典序只能用暴力染色.初始时均没有染 ...

  8. HDU - 5324:Boring Class (CDQ分治&树状数组&最小字典序)

    题意:给定N个组合,每个组合有a和b,现在求最长序列,满足a不升,b不降. 思路:三位偏序,CDQ分治.   但是没想到怎么输出最小字典序,我好菜啊. 最小字典序: 我们倒序CDQ分治,ans[i]表 ...

  9. 构造+暴力 Codeforces Round #283 (Div. 2) B. Secret Combination

    题目传送门 /* 构造+暴力:按照题目意思,只要10次加1就变回原来的数字,暴力枚举所有数字,string大法好! */ /************************************** ...

随机推荐

  1. C# 读取Excel中的数据到DataTable中

    原文地址:http://www.open-open.com/code/view/1420029490093 public DataTable ExcelToDS(string Path) { stri ...

  2. leetcode-easy-array-283 move zeros

    mycode  77.24% class Solution(object): def moveZeroes(self, nums): """ :type nums: Li ...

  3. Hibernate一级缓存之懒加载问题

    Hibernate的懒加载: 当用到数据的时候才向数据库查询,这就是hibernate的懒加载特性. 目的,为提高程序执行效率. 查询操作:get()方法/load()方法 (1)get()方法,及时 ...

  4. leetcode 102.Binary Tree Level Order Traversal 二叉树的层次遍历

    基础为用队列实现二叉树的层序遍历,本题变体是分别存储某一层的元素,那么只要知道,每一层的元素都是上一层的子元素,那么只要在while循环里面加个for循环,将当前队列的值(即本层元素)全部访问后再执行 ...

  5. Windows下对函数打桩,及Linux类似技术

    一个简单的桩实现类: #define JMPCODE_LENGTH 5 //x86 平坦内存模式下,绝对跳转指令长度 #define JMPCMD_LENGTH 1 //机械码0xe9长度 #defi ...

  6. postman杂记

    接到测试任务,测试6个接口 rap2 上的接口比较多,整体导出内容太多 就一个接口一个接口的,复制到了postman上 rap2部分接口,开发没有备注简介内容:通知开发备注下 对接口的理解,还是靠功能 ...

  7. 应用安全 - Web框架 - Apache Flink - 漏洞汇总

    SSV ID:SSV-98101 -- 类型: 文件上传导致远程代码执行   flink下载: https://www.apache.org/dyn/closer.lua/flink/flink-1. ...

  8. 成功安装 Visio 2016 和 Office 2016 的64位版本~~

    .XML是个很  的东西!!! 折腾了一下 Visio 2016_x64 和 Office 2016_x64,功夫不负! 首先,选对配置工具很重要. 之前总是失败是因为在官网下载的配置工具是给2019 ...

  9. OpenGL字体绘制

    /* glfont.hpp sdragonx 2019-08-15 00:03:33 opengl字体类,提供初学者参考学习 opengl初始化之后,创建字体 font.init(L"微软雅 ...

  10. RabbitMq学习1-介绍、安装和配置

    一.简介 1.MQ框架非常之多,比较流行的有RabbitMq.ActiveMq.ZeroMq.kafka,以及阿里开源的RocketMQ       2.AMQP是消息队列的一个协议. 3.Rabbi ...