[EC Final 2021] Future Coder(数学&规律)

题面翻译

题目描述

T T T 组数据,每组给出一个数 n n n n n n 个数 a 1 , a 2 , . . . , a n a_1,a_2,...,a_n a1,a2,...,an,求有多少个二元组 ( a i , a j ) (a_i,a_j) (ai,aj) 满足 a i a j < a i + a j a_ia_j<a_i+a_j aiaj<ai+aj

输入格式

第一行为一个数 T T T

接下来 T T T 组数据,每组数据第一行为一个数 n n n,第二行为 n n n 个数 a 1 , a 2 , . . . , a n a_1,a_2,...,a_n a1,a2,...,an

输出格式

T T T 行,为满足 a i a j < a i + a j a_ia_j<a_i+a_j aiaj<ai+aj 的二元组 ( a i , a j ) (a_i,a_j) (ai,aj) 的组数。

Translated from FurippuWRY

题目描述

Prof. Pang builds his famous coding team recently. To pursue a gold medal in ICPC, hundreds of pupils join his team. Unfortunately, one of Prof. Pang’s students believes that for any integers a a a and b b b, a × b ≥ a + b a\times b\ge a+b a×ba+b. To disprove this proposition, Prof. Pang writes n n n numbers a 1 , a 2 , … , a n a_1,a_2,\ldots, a_n a1,a2,,an on a paper and wants you to count how many pairs of numbers ( a i , a j ) (a_i, a_j) (ai,aj) ( 1 ≤ i < j ≤ n 1\le i < j\le n 1i<jn) satisfies a i × a j < a i + a j a_i\times a_j<a_i+a_j ai×aj<ai+aj.

输入格式

The first line contains a single integer T T T ( 1 ≤ T ≤ 1 0 6 1\le T\le 10^6 1T106) denoting the number of test cases.

For each test case, the first line contains a single integer n n n ( 1 ≤ n ≤ 1 0 6 1\le n\le 10^6 1n106). The second line contains n n n integers a 1 , a 2 , … , a n a_1, a_2, \ldots, a_n a1,a2,,an ( − 1 0 9 ≤ a i ≤ 1 0 9 -10^9\le a_i\le 10^9 109ai109).

It is guaranteed that the sum of n n n over all test cases will not exceed 1 0 6 10^6 106.

输出格式

For each test case, print one line containing the answer.

样例 #1

样例输入 #1

2
8
3 -1 4 1 -5 9 2 -6
1
0

样例输出 #1

19
0

解析

可以发现一个负数或者零,乘以正数必定符合题意,所以统计非正数的个数。

此外,还要考虑 1 1 1 的情况,即 1 1 1 乘一个正数同样符合题意,所以额外统计 1 1 1 的个数计算进去即可。

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define inf 1e18
const int mod=1e9+7;
const int N=2e5+5;
int n;
void solve(){
	cin>>n;
	int cnt=0,a=0; 
	for(int i=1;i<=n;i++){
		int x;
		cin>>x;
		if(x<=0) cnt++;
		else if(x==1) a++;
	}
	int t=n-cnt;
	cout<<t*cnt+t*a-(a+1)*a/2<<endl;
}
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int tt=1;
	cin>>tt;
	while(tt--) solve();
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值