poj 3748 位操作
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 8856 | Accepted: 3535 |
Description
Input
Output
Sample Input
12345678,0,3
Sample Output
1234567c
Source
做法一:
C++标准库:bitset 用法整理 :
http://happyboy200032.blog.163.com/blog/static/46903113201291252033712/
#include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
#include<bitset>//二进制类,bit位,初始为0
using namespace std;
int main(){
int r,x,y;
while(scanf("%x,%d,%d",&r,&x,&y)==){//输入16进制数
bitset<> b(r);
b.reset(x);
b.set(y);
b.set(y-);
b.reset(y-);
printf("%x\n",b.to_ulong());//将二进制转换为unsign long数值
}
return ;
}
做法二:
模拟
#include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
#include<bitset>
using namespace std;
int bit[];
int main(){
int r,x,y;
while(scanf("%x,%d,%d",&r,&x,&y)==){
memset(bit,false,sizeof(bit));
int i=;
for(;i<;i++){
bit[i]=r&;
r=r>>;
}
bit[x]=;
bit[y]=;
bit[y-]=;
bit[y-]=;
for(i=;i>=;i--){
r=r<<;
r=r|bit[i];
}
printf("%x\n",r);
}
return ;
}
poj 3748 位操作的更多相关文章
- POJ 3748:位操作
位操作 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8964 Accepted: 3581 Description 如 ...
- POJ - 3652 Persistent Bits
“模拟”类型,题型容易,使用bitset库对二进制逐位操作,初始化.十进制转二进制(unsigned int).位操作. POJ - 3652 Persistent Bits Time Limit: ...
- poj 1753 Flip Game 枚举(bfs+状态压缩)
题目:http://poj.org/problem?id=1753 因为粗心错了好多次……,尤其是把1<<15当成了65535: 参考博客:http://www.cnblogs.com/k ...
- 【转】POJ百道水题列表
以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight ...
- POJ 1321 棋盘问题(状态压缩DP)
不总结的话, 同一个地方会 WA 到死 思路: 状态压缩 DP. 1. s 表示压缩状态, 若第 i 列放了棋子, 那么该列置 1, 否则该列置 0. 假如 s = 3(0x011) 那么表示棋盘的第 ...
- POJ 3370. Halloween treats 抽屉原理 / 鸽巢原理
Halloween treats Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7644 Accepted: 2798 ...
- POJ 2356. Find a multiple 抽屉原理 / 鸽巢原理
Find a multiple Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7192 Accepted: 3138 ...
- POJ 2965. The Pilots Brothers' refrigerator 枚举or爆搜or分治
The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 22286 ...
- POJ 1753. Flip Game 枚举or爆搜+位压缩,或者高斯消元法
Flip Game Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 37427 Accepted: 16288 Descr ...
随机推荐
- Delphi Cookie获取及使用
以下方法为网上搜集整理,留做备份,随时更新 一:通过URL获取 CanGetIECookie(URL,g_cookie); function CanGetIECookie(const URL: ...
- ffmpeg用法小结,教你抓各大网站视频
最近受邀朋友帮忙需要抓取一段某酷电影,偶然间发现ffmpeg程序.说到此可能会有人提到you-get和youtube-dl,期间也接触了该两款程序,但是由于版权原因,该软件仅仅可以抓取前几分钟预览版, ...
- 该用li还是得用
如:这样子少一层是很好,但为了美观,后面都补上a,但鼠标经过也会有背景色,所以还是得多一层li 解决后:
- UML图基础
UML(Unified Model Language)统一建模语言,是对象管理组织(OMG)制定的一个通用的.可视化的建模标准语言,可以用来可视化.描述.构造和文档化软件密集型系统的各种工作.在学习设 ...
- 7,CountDownLatch 与 CyclicBarrier 的 区别
CountDownLatch : 一个同步辅助类,在完成一组正在其他线程中执行的操作之前,它允许一个或多个线程一直等待. 用给定的计数 初始化 CountDownLatch.由于调用了 countDo ...
- noip提高组模拟赛(QBXT)T2
T2count题解 [ 问题描述]: 小 A 是一名热衷于优化各种算法的 OIER,有一天他给了你一个随机生成的 1~n 的排列, 并定 义区间[l,r]的价值为: \[ \huge C_{l,r}= ...
- How to stop UITableView from clipping UITableViewCell contents in iOS 7
It looks like the view hierarchy changed slightly in ios7 for table view cells. You can try setting ...
- Thread类和Runnable接口的比较
Thread和Runnable的联系 Thread类的定义: public class Thread extends Object implements Runnable 联系:从Thread类的定义 ...
- centos的基本命令02
16:查看系统运行的进程 ps -ef 17:查看系统已开放的端口 netstat -tunlp 18:管道命令 ps -ef | grep tom # 查看系统中与tom相关的进程 19:grep过 ...
- 【算法笔记】B1049 数列的片段和
1049 数列的片段和 (20 分) 给定一个正数数列,我们可以从中截取任意的连续的几个数,称为片段.例如,给定数列 { 0.1, 0.2, 0.3, 0.4 },我们有 (0.1) (0.1, ...