#1178 : 计数

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://hihocoder.com/problemset/problem/1178

Description

Rowdark是一个邪恶的魔法师。在他阅读大巫术师Lich的传记时,他发现一类黑魔法来召唤远古生物,鱼丸。

魔法n能召唤类型i鱼丸当且仅当i能够被表示为x xor n*x对于某个正整数x和固定的n。

Rowdark想知道类型为[L,R]之间的鱼丸有多少种能被魔法n召唤。

Input

输入第一行包含个整数n(1 ≤ n ≤ 107)。

第二行包含两个整数,L, R(0 ≤ L ≤ R ≤ 107)。

Output

一行一个整数表示答案。

Sample Input

2

1 10

Sample Output

3

HINT

只有3(1 xor 2), 5(3 xor 6), 6(2 xor 4), 9(7 xor 14), 10(6 xor 12)满足要求。

题意

题解:

正着想不会,那我们就逆着想就好了~

代码:

#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define test freopen("test.txt","r",stdin)
#define maxn 100001
#define mod 10007
#define eps 1e-9
const int inf=0x3f3f3f3f;
const ll infll = 0x3f3f3f3f3f3f3f3fLL;
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
//************************************************************************************** int a[];
int main()
{
int n=read();
int l=read(),r=read();
for(int i=;i<=;i++)
{
ll tmp=(ll)(i)^(1LL*i*n);
if(tmp>r||tmp<)
continue;
a[tmp]=;
}
int ans=;
for(int i=l;i<=r;i++)
if(a[i]==)
ans++;
cout<<ans<<endl;
}

hihocoder #1178 : 计数 暴力的更多相关文章

  1. 暴力 hihoCoder 1178 计数

    题目传送门 /* 暴力:这题真是醉了,直接暴力竟然就可以了!复杂度不会分析,不敢写暴力程序.. 枚举x,在不重复的情况下+ans,超过范围直接break */ #include <cstdio& ...

  2. hihocoder 1178 : 计数

    #1178 : 计数 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Rowdark是一个邪恶的魔法师.在他阅读大巫术师Lich的传记时,他发现一类黑魔法来召唤远古生物, ...

  3. ACM学习历程—Hihocoder 1178 计数(位运算 && set容器)(hihoCoder挑战赛12)

    时间限制:10000ms 单点时限:1000ms 内存限制:256MB   描述 Rowdark是一个邪恶的魔法师.在他阅读大巫术师Lich的传记时,他发现一类黑魔法来召唤远古生物,鱼丸. 魔法n能召 ...

  4. BZOJ - 4066 KD树 范围计数 暴力重构

    题意:单点更新,大矩阵(\(n*n,n≤10^5\))求和 二维的KD树能使最坏情况不高于\(O(N\sqrt{N})\) 核心在于query时判断当前子树维护的区间是否有交集/当前子节点是否在块中, ...

  5. 【Foreign】朗格拉日计数 [暴力]

    朗格拉日计算 Time Limit: 10 Sec  Memory Limit: 128 MB Description Input Output 仅一行一个整数表示答案. Sample Input 5 ...

  6. HDU 5701 中位数计数 暴力

    老题了,附上黄学长链接一发,直接改改就AC了,http://hzwer.com/1216.html #include <cstdio> #include <iostream> ...

  7. 【luogu P3953 逛公园】 题解

    题目链接:https://www.luogu.org/problemnew/show/P3953 题外话:感觉2017年神题好多..这还不是最神的一道,真在考场上我也就写个最短路计数暴力了.现在在大佬 ...

  8. NOIP2017 【游记】

    一年过去,想起去年还是个傻b[今年也是],心里总是无限的感慨. 脑海里是日日夜夜在机房的身影,一题一题AC的激情 我等今年等了许久,虽然我是个蒟蒻,但我有梦想的憧憬 鲲鹏展翅翼向天,扶摇直上九万里. ...

  9. hihoCoder 1185 连通性·三(Tarjan缩点+暴力DFS)

    #1185 : 连通性·三 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 暑假到了!!小Hi和小Ho为了体验生活,来到了住在大草原的约翰家.今天一大早,约翰因为有事要出 ...

随机推荐

  1. 【LeetCode 234】Palindrome Linked List

    Given a singly linked list, determine if it is a palindrome. 思路: 用快慢指针找到链表中点,反转后半部分链表,然后与前半部分进行匹配,随后 ...

  2. 先声明再定义的必要性 .xml

    pre{ line-height:1; color:#9f1d66; background-color:#cfe4e4; font-size:16px;}.sysFunc{color:#5d57ff; ...

  3. leetcode:Roman to Integer(罗马数字转化为罗马数字)

    Question: Given a roman numeral, convert it to an integer. Input is guaranteed to be within the rang ...

  4. mybatis系列-14-延迟加载

    14.1     什么是延迟加载 resultMap可以实现高级映射(使用association.collection实现一对一及一对多映射),association.collection具备延迟加载 ...

  5. C++11 之 &quot; = delete &quot;

    1  缺省函数 设计一个类,没有成员函数 (member function),只有成员数据 (member data) class DataOnly { private: std::string st ...

  6. while (cin>>str)退出死循环

    今天在练习的时候突然发现了这个问题,百度之感觉还挺常见的,故记之! //题目描述 // //写出一个程序,接受一个十六进制的数值字符串,输出该数值的十进制字符串. // //输入描述 : //输入一个 ...

  7. poj 1005 I Think I Need a Houseboat

    #include <iostream> using namespace std; const double pi = 3.1415926535; int main() { ;; doubl ...

  8. HP ILO2 使用详细教程

    iLO是Intergrated Light-Out的缩写,是惠普特有的远程管理功能,目前最新的版本是iLO2.通过iLO2可以实现硬件级别的服务器远程管理,包括开关机.重启.服务器状态的监控.虚拟KV ...

  9. 转载-SQL中的where条件,在数据库中提取与应用浅析

    1        问题描述 一条SQL,在数据库中是如何执行的呢?相信很多人都会对这个问题比较感兴趣.当然,要完整描述一条SQL在数据库中的生命周期,这是一个非常巨大的问题,涵盖了SQL的词法解析.语 ...

  10. 二、 C#调用存储过程

    个人比较喜欢使用第二种传递参数的方法 1. 调用的方法 public DataTable ExceStoredProcedure (string strCom, SqlParameter[] comm ...