日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Codeforces Round #618 (Div. 2)-Non-zero

發布時間:2023/12/15 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Codeforces Round #618 (Div. 2)-Non-zero 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Guy-Manuel and Thomas have an array a of n integers [a1,a2,,an]. In one step they can add 1 to any element of the array. Formally, in one step they can choose any integer index i (1≤i≤n) and do ai:=ai+1.If either the sum or the product of all elements in the array is equal to zero, Guy-Manuel and Thomas do not mind to do this operation one more time.What is the minimum number of steps they need to do to make both the sum and the product of all elements in the array different from zero? Formally, find the minimum number of steps to make a1+a2++an≠0 and a1?a2? … ?an≠0.

Input

Each test contains multiple test cases.The first line contains the number of test cases t (1≤t≤103). The description of the test cases follows.The first line of each test case contains an integer n (1≤n≤100) — the size of the array.The second line of each test case contains n integers a1,a2,,an (?100≤ai≤100) — elements of the array .

Output

For each test case, output the minimum number of steps required to make both sum and product of all elements in the array different from zero.

Example
input

4 3 2 -1 -1 4 -1 0 0 1 2 -1 2 3 0 -2 1

output

1 2 0 2

Note

In the first test case, the sum is 0. If we add 1 to the first element, the array will be [3,?1,?1], the sum will be equal to 1 and the product will be equal to 3.In the second test case, both product and sum are 0. If we add 1 to the second and the third element, the array will be [?1,1,1,1], the sum will be equal to 2 and the product will be equal to ?1. It can be shown that fewer steps can't be enough.In the third test case, both sum and product are non-zero, we don't need to do anything.In the fourth test case, after adding 1 twice to the first element the array will be [2,?2,1], the sum will be 1 and the product will be ?4.

這個題是說通過最小的修改次數,是數列和不能為0,乘積不能為0;
那么也即數列中不存在0,如果存在0的一定要改,存在0的只能變成1,那我們考慮變成1之后,的和是否等于0,如果等于,就在修改1個,即cnt+1。

#include<bits/stdc++.h> using namespace std; const int N=5e5; #define read(a) scanf("%d",&a); int a[N]; int main() {int t;read(t);while(t--){int n;read(n);long long sum=0;int cnt=0;for(int i=1;i<=n;i++){cin>>a[i];sum+=(long long)a[i];if(a[i]==0) cnt++;}if(cnt==0){if(sum!=0) cout<<0<<endl;else cout<<1<<endl;}else {if(cnt+sum==0) cout<<cnt+1<<endl;else cout<<cnt<<endl;}} }

總結

以上是生活随笔為你收集整理的Codeforces Round #618 (Div. 2)-Non-zero的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 亚洲a一区 | 五月天免费网站 | 男人你懂的网站 | 国内毛片毛片毛片毛片毛片 | 亚洲伦理自拍 | 欧美色图视频在线 | 国产ts系列 | 成人自拍偷拍 | 九九热视频这里只有精品 | wwwxxx日本 | 四虎精品久久 | 黄色中文字幕在线观看 | 亚洲男女 | 深爱婷婷 | 欧洲亚洲激情 | av在线地址 | 艹男人的日日夜夜 | 色哟哟入口国产精品 | 久久97久久97精品免视看 | 九一国产在线 | 四虎午夜 | 在线国产欧美 | 一节黄色片 | 美女天天干 | 精品久久二区 | 日本精品网站 | 香蕉视频黄版 | 一个色亚洲 | 96亚洲精品久久久蜜桃 | 久久久久亚洲av片无码 | 成人高清视频免费观看 | 亚洲AV无码一区二区三区少妇 | 视频在线| 成人午夜视频在线 | 欧美天堂| 国产13页| 91嫩草视频在线观看 | 一区免费视频 | 久久久久久久久久久久国产精品 | 亚洲午夜精品视频 | 成av人片一区二区三区久久 | 日本在线观看一区 | 国产精品色综合 | 超碰精品在线观看 | 欧美又粗又大xxxxbbbb疯狂 | 毛茸茸亚洲孕妇孕交片 | 国产一区二区三区免费观看 | 亚洲自拍小视频 | 久久这里只精品 | 亚洲另类春色 | 久久66热这里只有精品 | 在线视频精品一区 | aise爱色av| 好吊色视频一区二区 | 一级美女黄色片 | 免费操人视频 | 亚洲综合视频一区 | 999久久久免费精品国产 | 在线麻豆视频 | 精品1区2区3区 | 大粗鳮巴久久久久久久久 | 俺来也在线视频 | 亚洲欧美日韩国产精品 | av中文字幕一区 | 国产精品久久77777 | 国产精品婷婷午夜在线观看 | 好爽快一点高潮了 | 91大神一区二区 | 亚洲专区欧美专区 | 麻豆精品一区 | 日韩在线观看网站 | 亚洲高潮无码久久 | 九九在线观看免费高清版 | 国内三级视频 | 爱看av在线| 久久精品99国产国产精 | mm1313亚洲精品| 台湾综合色 | av在线手机观看 | 久久香蕉影院 | 懂色av一区二区三区四区 | 日本一区二区三区精品视频 | 1000部拍拍拍18勿入免费视频 | 成人在线观看黄色 | 黄色1级片 | 日韩专区一区 | 妖精视频一区二区三区 | 欧美老肥妇做爰bbww | 夜夜艹天天干 | 午夜在线一区 | 日日操狠狠干 | 国产毛茸茸 | 丝袜脚交免费网站xx | 手机在线观看毛片 | 国产美女主播在线 | 偷偷色噜狠狠狠狠的777米奇 | 激情视频网站 | 情侣自拍av | 国产婷婷在线视频 |