【 BowWow and the Timetable CodeForces - 1204A 】【思维】
题目链接
可以发现
十进制4 对应 二进制100
十进制16 对应 二进制10000
十进制64 对应 二进制1000000
可以发现每多两个零,4的次幂就增加1.
用string读入题目给定的二进制数字,求出其长len,当len为奇数时,第一位为1,后面的位数如果都为0,则输出len,如果有一个不为0,则输出len+1;
当len为偶数时,则输出len。(之所以这样输出是因为题目给定4的次幂是从0开始的)
#include<iostream>
#include<string>
#include<cstdio>
using namespace std;
string s;
int main()
{
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
cin >> s;
int len = s.length();
if(len % 2 == 0)
printf("%d\n", len / 2);
else
{
int flag = 0;
for(int i = 1;i < len; i++)
{
if(s[i] == '1')
{
printf("%d\n", len / 2 + 1);
flag = 1;
break;
}
}
if(!flag)
printf("%d\n", len / 2);
}
}
【 BowWow and the Timetable CodeForces - 1204A 】【思维】的更多相关文章
- Codeforces Round #581 (Div. 2)A BowWow and the Timetable (思维)
A. BowWow and the Timetable time limit per test1 second memory limit per test256 megabytes inputstan ...
- CodeForces - 946D Timetable (分组背包+思维)
题意 n天的课程,每天有m个时间单位.若时间i和j都有课,那么要在学校待\(j-i+1\)个时间.现在最多能翘k节课,问最少能在学校待多少时间. 分析 将一天的内容视作一个背包的组,可以预处理出该天内 ...
- Codeforces 424A (思维题)
Squats Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Submit Statu ...
- Codeforces 1060E(思维+贡献法)
https://codeforces.com/contest/1060/problem/E 题意 给一颗树,在原始的图中假如两个点连向同一个点,这两个点之间就可以连一条边,定义两点之间的长度为两点之间 ...
- Queue CodeForces - 353D (思维dp)
https://codeforces.com/problemset/problem/353/D 大意:给定字符串, 每一秒, 若F在M的右侧, 则交换M与F, 求多少秒后F全在M左侧 $dp[i]$为 ...
- codeforces 1244C (思维 or 扩展欧几里得)
(点击此处查看原题) 题意分析 已知 n , p , w, d ,求x , y, z的值 ,他们的关系为: x + y + z = n x * w + y * d = p 思维法 当 y < w ...
- CodeForces - 417B (思维题)
Crash Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Submit Status ...
- CodeForces - 417A(思维题)
Elimination Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Submit ...
- CodeForces 625A 思维
题意是说一个人喝酒 有两种办法 买塑料瓶的 a块钱 喝了就没了 或者是买玻璃瓶的b块钱 喝完还能卖了瓶子c块钱 求最多能喝多少瓶 在开始判断一次 a与b-c的关系 即两种方式喝酒的成本 如果a< ...
随机推荐
- java calendar获取系统当前小时数
calendar获取系统当前小时数 24小时制 Calendar calendar = Calendar.getInstance(); int curHour24 = calendar.get(c ...
- Spring的NamedParameterJdbcTemplate的简单使用
原文地址:https://www.iteye.com/blog/itommy-2354746 Spring JDBC包提供了JdbcTemplate和它的两个兄弟SimpleJdbcTemplate和 ...
- GameZ游戏排名系统
GameZ游戏排名系统 GameZ为他们最新推出的游戏开通了一个网站.世界各地的玩家都可以将自己的游戏得分上传到网站上.这样就可以看到自己在世界上的排名.得分越高,排名就越靠前.当两个玩家的名次相同时 ...
- python(二)面向对象知识点
模块 别名 import my_module as xxx(别名) 先导入内置模块 再导入第三方模块 再导入自定义模块 from my_module(导入的文件) import *(变量) __all ...
- KB,MB,GB,TB,PB,EB,ZB,YB,BB
1 Bit = Binary Digit 8 Bits = 1 Byte 1024 Bytes = 1 Kilobyte 1024 Kilobytes = 1 Megabyte 1024 Megaby ...
- kubernetes支持local volume
目录 local volume 创建一个storage class 静态创建PV 使用local volume PV 动态创建PV local volume kubernetes从1.10版本开始支持 ...
- golang 学习笔记 -- 类型
int 和 uint的实际宽度会根据计算架构不同而不同,386下4个字节, amd64下8个字节 byte可看做uint8的别名类型 rune可看做int32的别名类型,专用于存储Unicode编码的 ...
- 【mysql】获取某个表所有列名【mybatis】
方法1:[仅指定表名] select COLUMN_NAME from information_schema.COLUMNS where table_name = 'your-table-name'; ...
- 局域网访问PHP项目网站 用IP地址进入
先在apache中的 httpd.conf中将 Allow from 127.0.0.1 修改为Allow from all 如果你的是Allow from all的话就不需要改 然后再将 Docum ...
- MySQL之命令行简单操作MySQL(二)
一:命令行连接数据库 打开终端,运行命令mysql -uroot -p (p后面加密码,可以直接加,也可以回车在下一行输入,为了不暴露密码,回车在下行输入 退出:exit或quit 查看版本信息: s ...