当前位置: 首页 > ops >正文

A. Dr. TC

time limit per test

1 second

memory limit per test

256 megabytes

In order to test his patients' intelligence, Dr. TC created the following test.

First, he creates a binary string∗∗ ss having nn characters. Then, he creates nn binary strings a1,a2,…,ana1,a2,…,an. It is known that aiai is created by first copying ss, then flipping the ii'th character (11 becomes 00 and vice versa). After creating all nn strings, he arranges them into a grid where the ii'th row is aiai.

For example,

  • If s=101s=101, a=[001,111,100]a=[001,111,100].
  • If s=0000s=0000, a=[1000,0100,0010,0001]a=[1000,0100,0010,0001].

The patient needs to count the number of 11s written on the board in less than a second. Can you pass the test?

∗∗A binary string is a string that only consists of characters 11 and 00.

Input

The first line of the input consists of a single integer tt (1≤t≤10001≤t≤1000) — the number of test cases.

The first line of each test case contains a single integer nn (1≤n≤101≤n≤10) — the length of the binary string ss.

The second line of each test case contains a single binary string ss of size nn.

Output

For each test case, output a single integer, the number of 11s on the board.

Example

Input

Copy

 

5

3

101

1

1

5

00000

2

11

3

010

Output

Copy

5
0
5
2
4

Note

The first example is explained in the statement.

For the second example, the only string written on the board will be the string 00; therefore, the answer is 00.

In the third example, the following strings will be written on the board: [10000,01000,00100,00010,00001][10000,01000,00100,00010,00001]; so there are five 11s written on the board.

解题说明:此题是一道数学题,找规律即可,首先统计出原来数字中包含多少个1,多少个0.翻转后就能发现总的1的数目是(n-1)*(1的个数)+(0的个数)

#include<stdio.h>
int main()
{int t;scanf("%d", &t);while (t--){int n, i, num;scanf("%d", &n);int sum = 0, arr[11];scanf("%d", &num);for (i = 0; i < n; i++){arr[i] = num % 10;sum += arr[i];num /= 10;}printf("%d\n", (sum * n) + n - (2 * sum));}return 0;
}

http://www.xdnf.cn/news/13430.html

相关文章:

  • 产品升级 | 新一代高性能数据采集平台BRICK2 X11,助力ADAS与自动驾驶开发
  • MatAnyone本地部署,视频分割处理,绿幕抠像(WIN/MAC)
  • YOLOv1 技术详解:正负样本划分与置信度设计
  • 【unitrix】1.1 密封模式(srcsealed.rs)
  • SQL29 验证刷题效果,输出题目真实通过率
  • Spring声明式事务生效是有条件滴!
  • 达梦数据库单机部署dmhs同步复制(dm8->kafka)
  • MFC 第1章:适配 WIndows 编程的软件界面调整
  • 如何诊断服务器硬盘故障?出现硬盘故障如何处理比较好?
  • 【沉浸式解决问题】Idea运行Junit测试中scanner无法获取控制台的输入内容
  • 山东大学软件学院项目实训-基于大模型的模拟面试系统-面试对话标题自动总结
  • 看安科瑞分布式光伏解决方案如何破解光伏痛点?
  • Python实战案例详解:基于计算器项目的扩展应用
  • 前端框架vue3的变化之处
  • API:解锁数字化协作的钥匙及开放实现路径深度剖析
  • HakcMyVM-Blackhat
  • Ubuntu 24.04 上安装与 Docker 部署 Sentinel
  • UE5 学习系列(六)导入资产包
  • BW非法字符处理
  • 智能空气流向控制系统SKLX的优化与实践
  • Hi3519DV500开发板适配新sensor的详细流程(最新版)
  • 96页PPT华为销售战略规划市场洞察品牌策略
  • Squid 代理服务器实战:解决动态 IP 访问第三方接口的生产级方案
  • 多系统合路器(POI)详解
  • 【数据结构】 优先级队列 —— 堆
  • 波形合成之C语言实现
  • NuGet 从入门到精进全解析
  • Intel Boot Guard
  • 系统集成自动化流程编排实现条件分支高级篇(二)
  • 实战使用docker compose 搭建 Redis 主从复制集群