poj 1023
来源:互联网 发布:android反编译apk mac 编辑:程序博客网 时间:2024/05/17 17:17
// Memory: 720K Time: 16MS
#include <iostream>#include <cmath>#include <cstdio> using namespace std;void strrev(char str[], int n){ for(int i=0; i < n/2; i++) { char t = str[i]; str[i] = str[n-i-1]; str[n-i-1] = t; }} char data[70];char re[70];int main(){ intn; scanf("%d",&n); while(n--) { long long len, num; scanf("%lld", &len); scanf("%s", data); scanf("%lld", &num); strrev(data, len); for (int i=1; i <= len; i++) { //cout << num%(int)pow(2.0,i+0.0); if (num % (long long)pow(2.0, i+0.0) != 0) { re[i-1] = '1'; if (data[i-1] == 'p') { num -= (long long)pow(2.0,i-1.0); } else { num += (long long)pow(2.0,i-1.0); } } else re[i-1] = '0'; } if (num != 0) printf("Impossible\n"); else { re[len] = 0; strrev(re, len); printf("%s\n", re); } } return0;}
刚开始加减那个地方没想通,后来发现人家是用num来减,减成0了就算成功
- poj 1023
- poj 1023
- poj 1023
- poj-1023
- POJ
- poj
- POJ
- POJ
- poj
- poj
- POJ
- POJ
- poj
- POJ
- POJ
- POJ
- POJ
- POJ
- 对象与XML,序列化与反序列化
- 细说学生管理系统(二)
- (droid分享)新浪微博开发系列【九】之开发者信息显示和程序退出
- 敲代码,看人生
- 10308 - Roads in the North--不好!
- poj 1023
- request_mem_region,ioremap 和phys_to_virt()
- poj1185 炮兵阵地 状态压缩dp
- Using FXML to Create a User Interface 使用FXML创建用户界面
- 抽象类与接口的关系
- 全志Android A10技术论坛推广
- TCP协议之Data解析
- (droid分享)新浪微博开发系列【十】 之发送微博
- SQL网上一些浏览(2)