CF1206B Make Product Equal One



思路

有一个很显然的思路就是分正负

如果是零的话,我们就把他转化成1,反正答案一定会+1

如果是正数,就传话为1

如果是负数,就转化为-1

如果负数的个数是偶数个,那当然最好,如果是奇数个,那就处理一下


#include <bits/stdc++.h>
#define int long long
using namespace std ;
int n , A , B , C ,ans = 0 , lop = 1 ;
signed main () {
	cin >> n ;
	for(int i = 1 ; i <= n ; i ++) {
		int x ;cin >> x ;
		if(!x) C ++ ;
		else if(x > 0) {
			ans += x-1 ;
		}else if(x < 0) {
			ans += -1-x ;
			lop *= -1 ;
		}
	}
	if(lop == -1 && !C) {
		ans += 2 ;
	}
	cout << ans + C<<endl ;
	return 0 ;
}

溜了溜了

原文地址:https://www.cnblogs.com/lyt020321/p/11393379.html