POJ 3748:位操作
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 8964 | Accepted: 3581 |
Description
Input
Output
Sample Input
12345678,0,3
Sample Output
1234567c
做完这个题目AC的时候,再看其它人discuss的时候。哭的心都有了。自己竟然模拟做。。。
各种WA,RE都搞出来了。
。。受不了了。代码各种幼稚我也不优化了。。。
代码:
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
using namespace std; int wei[10000]; void change_to(char R[10000])
{
int i,j;
for(i=7;i>=0;i--)
{
int temp=R[i];
for(j=0;j<=3;j++)
{
wei[(7-i)*4+j]=temp&1;
temp=temp>>1;
}
}
} void change(int x,int y)
{
if(x>=0&&x<=31)
wei[x]=0;
if(y>=2)
{
wei[y]=1;
wei[y-1]=1;
wei[y-2]=0;
}
else if(y==1)
{
wei[y]=1;
wei[y-1]=1;
}
else
wei[y]=1; } void solve()
{
char temp;
int i;
int flag=1;
for(i=31;i>=3;i=i-4)
{
int sum= wei[i]*8 + wei[i-1]*4 + wei[i-2]*2 + wei[i-3];
if(sum<=9 && sum>=0)
{
temp=sum+'0';
}
else
{
temp=sum+87;
}
if(temp=='0'&&flag==1)
{
}
else
{
flag=0;
cout<<temp;
}
}
} int main()
{ char R[10000],temp_R[10000];
char temp;
int x,y,i=0,j,k; memset(R,0,sizeof(R)); while(scanf("%c",&temp_R[i]),temp_R[i++]!=',');
i--;
j = 8-i;
k = 0;
for(i=j;i<8;i++)
{
R[i] = temp_R[k++];
}
for(x=0;x<8;x++)
{
if(R[x]>='0'&&R[x]<='9')
R[x]=R[x]-'0';
else if(R[x]>=97)
R[x]=R[x]-'a'+10;
}
scanf("%d,%d",&x,&y); change_to(R);
change(x,y);
solve(); cout<<endl; return 0;
}
话说位运算真是简单啊。%x真是方便啊,别总认准%d啊。
。
。
代码:
#include <iostream>
#include <cstdio> using namespace std; int main() {
unsigned int r, x, y; while(scanf_s("%x,%d,%d", &r, &x, &y) == 3) {
r = r & (~(1<<x));//将r的x位置为0
r = r | (1<<y);//将r的y位置为1
r = r | (1<<(y-1));
r = r & (~(1<<y-2));
printf("%x\n", r);
} return 0;
}
POJ 3748:位操作的更多相关文章
- poj 3748 位操作
位操作 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8856 Accepted: 3535 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 ...
随机推荐
- flask中的蓝图(BluePrint)
蓝图,听起来就是一个很宏伟的东西 在Flask中的蓝图 blueprint 也是非常宏伟的 它的作用就是将 功能 与 主服务 分开怎么理解呢? 比如说,你有一个客户管理系统,最开始的时候,只有一个查看 ...
- “浪潮杯”第九届山东省ACM大学生程序设计竞赛重现赛 C-Cities
题目描述:There are n cities in Byteland, and the ith city has a value ai. The cost of building a bidirec ...
- go语言Notepad++简易开发环境搭建(windows)
1.下载安装go语言:https://golang.org/dl/选择对应的平台,建议使用msi安装包,这个会帮你配置好环境变量(也许需要重启)对应的环境变量有: GOROOT - C:\Go\PAT ...
- 入门开发工具idea常见问题之选项中没有servlet
1.在maven中如果创建不了servlet,在project Setting旁边的添加一个web选项,就可以创建servlet了. 初次接触这个陌生的工具还是不太好弄.
- 回收maven私仓过期垃圾
login->scheduled tasks->add
- cplusplus系列>utility>pair
http://www.cplusplus.com/reference/utility/pair/ 用于存储一对异构对象 // Compile: g++ -std=c++11 pair.cpp #inc ...
- Python--10、进程知识补充
守护进程 基于进程启动的子进程,会和主进程一起结束.主进程结束的依据是程序的代码执行完毕. #创建守护进程p=Process(task) p.daemon = True p.start() 子进程需要 ...
- Leetcode0006--ZigZag Conversion
[转载请注明]https://www.cnblogs.com/igoslly/p/9017638.html 来看一下题目: The string "PAYPALISHIRING" ...
- JS高级——变量提升
JS执行过程 1.首先是预解析:预解析过程最重要的是提升,在JavaScript代码在预解析阶段,会对以var声明的变量名,和function开头的语句块,进行提升操作 2.执行操作 全局中解析和执行 ...
- 怎样用Fiddler模拟网络超时
转自:http://materliu.github.io/all/web/2014/04/28/fiddler-timeout.html 用fiddler模拟网络请求超时 用fiddler模拟网络 ...