当前位置: 首页 > 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;
}

相关文章:

  • 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、主从同步)
  • 山西网站建设企业/创建属于自己的网站
  • 做网站如何被收录/国家职业技能培训学校
  • 中国建设银行产品信息网站/刷外链
  • 个人建站的app哪里有卖/外链系统
  • 万户网络待遇怎么样/seo短视频网页入口
  • 做胎儿羊水鉴定网站/关键词排名提升工具