链接:https://www.nowcoder.com/acm/contest/116/H
来源:牛客网

题目描述

Once there was a king called XOR, he had a lot of land. Because of his name, he likes to play XOR games.

One day, he whimpered and wanted to establish N cities on that vast expanse of land, numbered 0, 1, 2..., N-1. He wanted to connect all the cities. If city A can reach City B through zero or one or several cities, then A and B are connected. The cost of repairing a road in City A and City B is the XOR value of number of City A and number of City B. This King XOR wanted to figure out the minimum cost for connecting all of the N cities.

Of course, like a fairy tale read as a child, there will be corresponding rewards after helping the king. If you help the king solve his problems, he will improve your ranking in the competition.

输入描述:

There are multi test cases
each test cases contains an integer N (2 ≤N≤ 20000), the number of cities the king wants to establish.

输出描述:

For each test case, print the minimum cost for connecting all of the N cities in one line.

输入例子:
4
输出例子:
4

-->

示例1

输入

4

输出

4

说明

The weightof the minimum cost is 1+2+1=4 In the Sample Example.

题目的原意应该是求一个最小生成树。两点之间的权值就是点编号的异或值。

直接按题目意思来肯定是不行的,建不了这么大的图。。

然后按照最小生成树的思想想一下就会发现,由于两点之间的权值是固定的,那么n个点得到最小生成树的结果其实就是在n-1个点的基础上加上n-1这个点连接0~n-2中的最小权值,由于连接的点都比n-1小,那么与n-1异或值最小的m,应满足 其二进制中除开n-1的二进制数中最后一个1的位置不同,其他位都相同。

毕竟异或是相同就为0,不同就为1。

emmmm 然后就直接打表处理~~

// Asimple
#include <bits/stdc++.h>
#define debug(a) cout<<#a<<" = "<<a<<endl
using namespace std;
typedef long long ll;
const int maxn = + ;
ll T, n, sum, num, m, t, len, ans;
ll fa[maxn]; ll qpow(ll n) {
ll ans = ;
ll a = ;
while( n ) {
if( n& ) ans *= a;
a = a*a;
n >>= ;
}
return ans;
} ll count(ll n) {
ll ans = ;
while( n% == ) {
n /= ;
ans ++;
}
return ans;
} void init() {
fa[] = ;
for(int i=; i<maxn; i++) {
fa[i] = fa[i-] + qpow(count(i-));
}
} void input() {
init();
while( ~scanf("%d", &n) ){
cout << fa[n] << endl;
} } int main() {
input();
return ;
}

新疆大学ACM-ICPC程序设计竞赛五月月赛(同步赛) H XOR的更多相关文章

  1. A. Srdce and Triangle--“今日头条杯”首届湖北省大学程序设计竞赛(网络同步赛)

    如下图这是“今日头条杯”首届湖北省大学程序设计竞赛的第一题,作为赛后补题 题目描述:链接点此 这套题的github地址(里面包含了数据,题解,现场排名):点此 Let  be a regualr tr ...

  2. I. Five Day Couple--“今日头条杯”首届湖北省大学程序设计竞赛(网络同步赛)

    题目描述:链接点此 这套题的github地址(里面包含了数据,题解,现场排名):点此 链接:https://www.nowcoder.com/acm/contest/104/H来源:牛客网 题目描述 ...

  3. D. Who killed Cock Robin--“今日头条杯”首届湖北省大学程序设计竞赛(网络同步赛)

    题目描述:链接点此 这套题的github地址(里面包含了数据,题解,现场排名):点此 题目描述 由于系统限制,C题无法在此评测,此题为现场赛的D题 Who killed Cock Robin? I, ...

  4. 新疆大学ACM-ICPC程序设计竞赛五月月赛(同步赛) F.猴子排序的期望

    题目链接:https://www.nowcoder.com/acm/contest/116/F 题目描述 我们知道有一种神奇的排序方法叫做猴子排序,就是把待排序的数字写在卡片上,然后让猴子把卡片扔在空 ...

  5. 新疆大学ACM-ICPC程序设计竞赛五月月赛(同步赛)F 猴子排序的期望【Java/高精度/组合数学+概率论】

    链接:https://www.nowcoder.com/acm/contest/116/F 来源:牛客网 题目描述 我们知道有一种神奇的排序方法叫做猴子排序,就是把待排序的数字写在卡片上,然后让猴子把 ...

  6. 新疆大学ACM-ICPC程序设计竞赛五月月赛(同步赛)C 勤奋的杨老师【DP/正反LIS/类似合唱队形】

    链接:https://www.nowcoder.com/acm/contest/116/C 来源:牛客网 题目描述 杨老师认为他的学习能力曲线是一个拱形.勤奋的他根据时间的先后顺序罗列了一个学习清单, ...

  7. 新疆大学ACM-ICPC程序设计竞赛五月月赛(同步赛)B 杨老师的游戏【暴力/next-permutation函数/dfs】

    链接:https://www.nowcoder.com/acm/contest/116/B 来源:牛客网 题目描述 杨老师给同学们玩个游戏,要求使用乘法和减法来表示一个数,他给大家9张卡片,然后报出一 ...

  8. 新疆大学ACM-ICPC程序设计竞赛五月月赛(同步赛)- 勤奋的杨老师(最长递增子序列)

    链接:https://www.nowcoder.com/acm/contest/116/C来源:牛客网 题目描述 杨老师认为他的学习能力曲线是一个拱形.勤奋的他根据时间的先后顺序罗列了一个学习清单,共 ...

  9. 新疆大学ACM-ICPC程序设计竞赛五月月赛(同步赛)- XOR(二进制使用)

    链接:https://www.nowcoder.com/acm/contest/116/H来源:牛客网 题目描述 Once there was a king called XOR, he had a ...

随机推荐

  1. LeetCode 50 - Pow(x, n) - [快速幂]

    实现 pow(x, n) ,即计算 x 的 n 次幂函数. 示例 1: 输入: 2.00000, 10输出: 1024.00000 示例 2: 输入: 2.10000, 3输出: 9.26100 示例 ...

  2. 将win7 设置为 NTP服务器

    1. 修改注册表项 HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\TimeProviders\NtpServer Enabl ...

  3. sqlhelp3

    using System; using System.Collections; using System.Collections.Specialized; using System.Data; usi ...

  4. jQuery中的$.getJSON、$.ajax、$.get、$.post的区别

    jQuery中的$.getJSON.$.ajax.$.get.$.post的区别 使用见Flask(python)异步(ajax)返回json格式数据 ①.$.getJSON $.getJSON()是 ...

  5. ajax 未加载出数据时,显示loding,数据显示后,隐藏loading

    $("#CreateReport").click(function () { // RptID,Template,TemplateType,FileName var RptID = ...

  6. (李南江jQuery+Ajax)第一章:初识jQuery

    第一章:初识jQuery 一.原生的JS与jQuery的区别 <!DOCTYPE html> <html lang="en"> <head> & ...

  7. mysql关于排序值的问题,指定排序值

    SELECT a.* FROM `catalog_eav_attribute` ea JOIN `eav_attribute` a ON ea.`attribute_id`=a.`attribute_ ...

  8. ajax php 验证注册用户名是否存在

    1.在"test"数据库中,建立一张名为"user"的表. sql语句: create table `user`( `id` ) not null auto_i ...

  9. 3.远程连接工具、JDK安装

    1.实现Centos和windows的文件传输,可以使用Xshell和Xftp(实验指导使用的是winscp). (1).可以使用Xshell远程登陆Linux,具体安装过程略. (2).登陆Cent ...

  10. 学号 20175313 《实验三 敏捷开发与XP实践》实验报告

    目录 实验三 敏捷开发与XP实践 一.实验内容 二.实验步骤 四.心得体会 五.码云链接 六.参考资料 实验三 敏捷开发与XP实践 一.实验内容 (1)编码标准 在IDEA中使用工具(Code-> ...