当前位置:网站首页>Zcmu--5083: number pairs of ly (C language)
Zcmu--5083: number pairs of ly (C language)
2022-07-24 16:32:00 【Little why】
Description
ly Yes n Number , Now she wants to know this n Take a logarithm out of the number (x,y) Satisfy x%3 <= y%3 What's the number of plans for . among , In this sequence ,x It's better than y front .
Input
Enter two lines , The first line contains a positive integer n , Represents the number of numbers .
The second line contains n A positive integer ,ai Represents the second in the sequence i Number .
Title assurance 1 <= n <= 10^5, 1 <= ai <=10^9
Output
Output one line , It's an integer , For the answer .
Sample Input
4
1 3 4 2
Sample Output
5
analysis :1. requirement x%3 <= y%3, So we can notice , We can put the whole sequence all %3, Then I found that only 0,1,2 Three situations !
2. because x The location should be y front , So the question actually lets us ask each a[ i ] How many of the following sequences are greater than a[ i ] The sum of the number of , So we have to traverse from the back , At the same time, the record is updated 0,1,2 Existing quantity a,b,c. If a[ i]=0, that a[ i ] The contribution to the answer is a+b+c, then a++. If a[i]=1, Contribution is b+c, then b++,a[i]=2, Contribution is c,c++;
3. The maximum number of schemes exceeds int 了 , We use long long.
#include <stdio.h>
int k[100005];
int main()
{
int n,i,l,a=0,b=0,c=0; //abc Record the existing 0,1,2 Number
long long s=0; // Record the number of schemes
scanf("%d",&n);
for(i=0;i<n;i++) scanf("%d",&l),k[i]=l%3;// All modules 3 Deposit in
for(i=n-1;i>=0;i--){ // Start from the back
if(k[i]==0) s+=a+b+c,a++;
else if(k[i]==1) s+=b+c,b++;
else if(k[i]==2) s+=c,c++;
}
printf("%lld\n",s);
return 0;
}
边栏推荐
- After data management, the quality is still poor
- MySQL converts strings to numeric types and sorts them
- EventLoop event loop mechanism
- Causes and solutions of QT signal and slot connection failure
- .net review the old and know the new: [6] what is LINQ
- Best practices for preventing XSS in PHP web applications
- How to deal with the start and end times in mybatics
- 15、ARM嵌入式系统:如何用PC调试单板
- Qt键盘事件(二)——长按按键反复触发event事件问题解决
- Hping3 installation and use
猜你喜欢

thinkphp3.2.5无法跳转到外部链接

Win10 download address

Caikeng Alibaba cloud Kex_ exchange_ identification: read: Connection reset by peer

Jupyter uses tips

Jing Wei PS tutorial: basic part a

REST风格

ArcGIS pixel size changed from 0.00025 to meters

Creation and inheritance of JS class

Using native JS to realize magnifying glass function

Thinkphp3.2.5 cannot jump to external links
随机推荐
.NET 测试框架 xUnit,MSTest, Specflow 使用经验汇总
Dongfang Guangyi refuted the rumor late at night, saying that the news that the hammer was filed for investigation was untrue!
Use of ec200u-cn module
ZBar source code analysis - img_ scanner. c | [email protected]
Analysis of double pointer sliding window method and solution of leetcode related problems
GEO satellite data download
文件浏览器?Qt也可以实现!
[leetcode] skillfully use bit operation
Mcd12q1 data shows multiple classifications in envi
EF data migration
Software recommendation - Mechanical Major
15、ARM嵌入式系统:如何用PC调试单板
Qt键盘事件(一)——检测按键输入
Rest style
我们为什么要推出Getaverse?
Ligerui table control grid changes the color of rows (cells) according to the content
Using native JS to realize magnifying glass function
Picture browser? QT can also be achieved!
Envi5.3 open GF-1 WFV data
【机器学习基础】——另一个视角解释SVM