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 ...
随机推荐
- 实战iOS7之NSURLSession
NSURLSession VS NSURLConnection NSURLSession可以看做是NSURLConnection的进化版,其对NSURLConnection的改进点有: * 根据每个S ...
- uwsgi启动报错WARNING: Can't find section "uwsgi" in INI configuration file autotestsite_uwsgi.ini
提示配置文件头部找不到 [uwsgi] 解决: 在最上方加上[uwsgi],有时候明明有标识,但是还是提示,那就再加一个
- Razor TagHelper实现Markdown转HTML
Markdown是一种可以使用普通文本编辑器编写的标记语言,通过简单的标记语法,它可以使普通文本内容具有一定的格式. 用途 Markdown的语法简洁明了.学习容易,而且功能比纯文本更强,因此有很多人 ...
- MFC学习(三):项目学习
1. 概述 MFC程序由CWinApp.MainFrm(含Menu,可用CSplitterWndEx分割).众多Dialog等组成. MFC既可以使用纯Dialog的形式,也可以使用Document+ ...
- RabbitMq初探——php的一个demo
<?php /** * Created by PhpStorm. * Date: 2017/10/17 * Time: 16:21 */ class Rabbit { public functi ...
- WebGL 一
WebGL绘制窗口 <html><head><title>OpenGL Test</title> </head><body>&l ...
- 配合前端开发,调试前端页面bug
同事开发的H5页面 在iOS10.1的手机上会有bug 先下载ios10.1的模拟器,安装到xcode上,注意给电脑腾出足够的空间 https://stackoverflow.com/questio ...
- “全栈2019”Java第四十一章:static关键字
难度 初级 学习时间 10分钟 适合人群 零基础 开发语言 Java 开发环境 JDK v11 IntelliJ IDEA v2018.3 文章原文链接 "全栈2019"Java第 ...
- 如何构建debian包
1)安装dh_make如下: sudo apt-get intasll aptitude sudo aptitude install dh_make 2)以jsoncpp为例,说明如何生 ...
- ajax 提交 json格式数据到后台
例子:$.ajax({ type: 'POST', url: "/ROOT/modify.do", contentType: "application/json" ...