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

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.dtcms.com/a/244367.html

相关文章:

  • RPG24.设置武器伤害(二):将效果应用于目标
  • RabbitMQ可靠和延迟队列
  • 接收rabbitmq消息
  • 中心化交易所(CEX)架构:高并发撮合引擎与合规安全体系
  • [蓝桥杯 2024 国 Python B] 设计
  • TripGenie:畅游济南旅行规划助手:个人工作纪实(二十四)
  • Arduino入门教程:1、Arduino硬件介绍
  • LAN、WAN、WLAN、VLAN 、VPN对比
  • Java异步编程深度解析:从基础到复杂场景的难题拆解
  • 动态多目标进化算法:VARE(Vector Autoregressive Evolution)求解DF1-DF14,提供完整MATLAB代码
  • [服务器] Amazon Lightsail SSH连接黑屏的常见原因及解决方案
  • 曼昆《经济学原理》第九版 第十七章寡头垄断
  • 【leetcode】36. 有效的数独
  • 【Axure高保真原型】中继器表格更多操作
  • API:解锁数字化协作的钥匙及开放实现路径深度剖析
  • 产品升级 | 新一代高性能数据采集平台BRICK2 X11,助力ADAS与自动驾驶开发
  • 【AI】模型vs算法(以自动驾驶为例)
  • RPA与Agent技术如何结合,以实现跨系统、跨平台的工作流程自动化?
  • 本地docker部署的dify,不用git命令如何无损升级?
  • Redis分布式缓存(RDB、AOF、主从同步)
  • ArcGIS中坐标系一致但图层无法重叠问题解决
  • JavaWeb期末速成
  • 一套基于Apple watch电话手表包含150个覆盖商务、健康、爱好、定位、时钟、挂件的移动端UI界面的psd
  • GoldenDB简述
  • Vue ⑧-Vue3 | 组合式API
  • 产业园如何精准招商?
  • 【Pandas】pandas DataFrame notna
  • DAY 46 超大力王爱学Python
  • RFID测温芯片在新能源电池管理中的创新应用
  • 电路图识图基础知识-行程开关自动往返运行控制电路详解(二十三)