atcoder ABC 359-B题详解

atcoder ABC 359-B题详解

Problem Statement

There are 2N people standing in a row, and the person at the i-th position from the left is wearing clothes of color Ai. Here, the clothes have N colors from 1 to N, and exactly two people are wearing clothes of each color.

Find how many of the integers i=1,2,…,N satisfy the following condition:

There is exactly one person between the two people wearing clothes of color i.

Constraints

2≤N≤100
1≤Ai≤N
Each integer from 1 through N appears exactly twice in A.
All input values are integers.

Input

The input is given from Standard Input in the following format:

N
A1 A2 … A2N

Output

Print the answer.

Sample Input 1

3
1 2 1 3 2 3

Sample Output 1

2
There are two values of i that satisfy the condition: 1 and 3.

In fact, the people wearing clothes of color 1 are at the 1st and 3rd positions from the left, with exactly one person in between.

Sample Input 2

2
1 1 2 2

Sample Output 2

0
There may be no i that satisfies the condition.

Sample Input 3

4
4 3 2 3 2 1 4 1

Sample Output 3

3

思路分析:

本题需要求解中间的那个数边上的两个数一样的个数,可以开vector直接来求解。

code:

#include <iostream>
#include <vector>
using namespace std;
vector<int>v;
int n;
int a;
int ans=0;
int main(){
    cin>>n;
    for(int i=0;i<2*n;i++){
        cin>>a;
        v.push_back(a);
    }
    for(int i=0;i<2*n;i++){
        if(v[i]==v[i+2]){
            ans++;
        }
    }
    cout<<ans;
}
  • 7
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值