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 ...
随机推荐
- MFC学习篇(二):error LNK2005 及其解决方法
环境:MFC条件下添加原有代码 >nafxcwd.lib(afxmem.obj) : error LNK2005: @YAPAXI@Z) already defined in LIBCMTD.l ...
- 在vSphere Client上安装虚拟机工具VMware Tools
一.什么是虚拟机工具 VMware Tools是一套安装在虚拟机操作系统中的实用程序.VMware Tools可提高虚拟机的性能,并在 VMware产品中实现多个易于使用的功能. 尽管客户机操作系统在 ...
- zblog插件增加后台导航栏的方法
有时我们经常需要对插件进行设置,但是又不能让用户去做这些,那么下面的方法将会给插件增加在后台导航栏显示的功能 首先打开对应插件的文件夹,找到对应插件的 include.php 文件 将下面的代码粘 ...
- [Windows Server 2012] PHPWind安全设置
★ 欢迎来到[护卫神·V课堂],网站地址:http://v.huweishen.com★[护卫神·V课堂]是护卫神旗下专业提供服务器教学视频的网站,每周更新视频. ★ 本节我们将带领大家:PHPWin ...
- [Windows Server 2008] 安装网站伪静态
★ 欢迎来到[护卫神·V课堂],网站地址:http://v.huweishen.com★ 护卫神·V课堂 是护卫神旗下专业提供服务器教学视频的网站,每周更新视频.★ 本节我们将带领大家:安装IIS伪静 ...
- 【技术累积】【点】【java】【26】@Value默认值
@Value 该注解可以把配置文件中的值赋给属性 @Value("${shit.config}") private String shit; 要在xml文件中设置扫描包+place ...
- HDU_4826_dp
Labyrinth Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- codeforces_731C_[dfs][并查集]
C. Socks time limit per test 2 seconds memory limit per test 256 megabytes input standard input outp ...
- HDU_3308_线段树_区间合并
LCIS Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- DOCKER - POD操作
强制删除 Terminating 的pod kubectl delete -n <namespace> <pod podname> --grace-period=0 --fo ...