Educational Codeforces Round 94 (Rated for Div. 2) D(思维)
题目:
You are given an array a1,a2…an. Calculate the number of tuples (i,j,k,l) such that:
1≤i<j<k<l≤n;
ai=ak and aj=al;
Input
The first line contains a single integer t (1≤t≤100) — the number of test cases.
The first line of each test case contains a single integer n (4≤n≤3000) — the size of the array a.
The second line of each test case contains n integers a1,a2,…,an (1≤ai≤n) — the array a.
It’s guaranteed that the sum of n in one test doesn’t exceed 3000.
Output
For each test case, print the number of described tuples.
Example
inputCopy
2
5
2 2 2 2 2
6
1 3 3 1 2 3
outputCopy
5
2
Note
In the first test case, for any four indices i<j<k<l are valid, so the answer is the number of tuples.
In the second test case, there are 2 valid tuples:
(1,2,4,6): a1=a4 and a2=a6;
(1,3,4,6): a1=a4 and a3=a6.
题目大意: 找到满足条件的所有组合
1≤i<j<k<l≤n;
ai=ak and aj=al;
思路 :枚举j和l,然后用num来统计 j到l 有多少种组合。
cnt数组 记录好 j下标前面 出现过多少次这个数。
因为数据比较小,直接o(n^2).
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <queue>
#include <cstdlib>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#define INF 0x3f3f3f3f3f3f3f3f
#define inf 0x3f3f3f3f
#define FILL(a,b) (memset(a,b,sizeof(a)))
#define re register
#define lson rt<<1
#define rson rt<<1|1
#define lowbit(a) ((a)&-(a))
#define ios std::ios::sync_with_stdio(false);std::cin.tie(0);std::cout.tie(0);
#define fi first
#define rep(i,n) for(int i=0;(i)<(n);i++)
#define rep1(i,n) for(int i=1;(i)<=(n);i++)
#define se secondusing namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pii;
const ll mod=998244353;
const ll N =3e6+10;
const double eps = 1e-5;
const double pi=acos(-1);
ll gcd(ll a,ll b){return !b?a:gcd(b,a%b);}
int dx[4]= {-1,0,1,0}, dy[4] = {0,1,0,-1};
ll n,cnt[10005],a[10005],res,num;void solve()
{cin>>n;res=0;memset(cnt,0,sizeof(cnt));for(int i=1;i<=n;i++){cin>>a[i];}for(int j=1;j<n;j++){num=0;for(int l=j+1;l<=n;l++){if(a[j]==a[l]){res+=num;}num+=cnt[a[l]];}cnt[a[j]]++;}cout<<res<<endl;
}
int main()
{iosint T;cin>>T;//T=1;while(T--){solve();}return 0;
}
Educational Codeforces Round 94 (Rated for Div. 2) D(思维)相关推荐
- 枚举 ---- B. RPG Protagonist[Educational Codeforces Round 94 (Rated for Div. 2)]数学枚举
B. RPG Protagonist 题目大意:就是你有两个人,每个人都有一个最大的体力值p和f,这两个人要去搬运剑和盾牌,剑的数量是cnts,盾的数量是cntw,每个剑的重量是是s,每个盾的重量是w ...
- 枚举 ---- D. Zigzags[ Educational Codeforces Round 94 (Rated for Div. 2)]思维枚举优化4重循环
D. Zigzags 题目大意:就是给你i<j<k<l并且aj=al&&ai=aki<j<k<l并且a_j=a_l \&\& a_i ...
- Educational Codeforces Round 94 (Rated for Div. 2)
这次做了ABCD,今天下午就要上学去了溜了溜了,早上起来补的题解. A - String Similarity 分析可知可构造w[i]=s[2*i]即可满足题意 #define IO ios::syn ...
- Educational Codeforces Round 94 (Rated for Div. 2)题解ABCD
A. String Similarity 题目传送门 String Similarity 题目大意 给你一个n和一个长度为2∗n−12*n-12∗n−1的01字符串,对于给定字符串,你需要构造一个长度 ...
- Educational Codeforces Round 90 (Rated for Div. 2)(D 思维 E 打表)
题目链接 D. Maximum Sum on Even Positions 题意:给你n长度的数组a 要求翻转 子区间 使得 偶数上的数之和尽量最大. 做法:用偶数位置减去奇数位置的值 就相当 ...
- Educational Codeforces Round 67 (Rated for Div. 2)(D思维题 线段树/E树形dp(换根dp) 二次扫描与换根法)
心得 D写了个假算法被hack了wtcl- E据涛神说是二次扫描与换根法,看了看好像和树形dp差不多 F概率dp G费用流 回头再补 思路来源 马老师 归神 贤神等代码 http://www.mami ...
- Educational Codeforces Round 90 (Rated for Div. 2)(A, B, C, D, E)
Educational Codeforces Round 90 (Rated for Div. 2) Donut Shops 思路 分三种情况: a==c/ba == c / ba==c/b这个时候两 ...
- Educational Codeforces Round 114 (Rated for Div. 2) (A ~ F)全题解
整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Educational Codeforces Round 114 (Rated for Div. 2) ...
- Educational Codeforces Round 106 (Rated for Div. 2)(A ~ E)题解(每日训练 Day.16 )
整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 目录 Educational Codeforces Round 106 (Rated for Div. ...
最新文章
- 如何有效地提升 JavaScript 水平?
- DHCP服务器的配置详细说明
- win7+ubuntu 13.04双系统安装方法
- css中实现div的显示和隐藏
- 谷歌cloud_通过使用Google Cloud ML大规模提供机器学习模型,我们学到了什么
- [html]请描述HTML元素的显示优先级
- 红皮书--调试及修复
- AJAX请求中payload和formdata两种方式
- JVM 垃圾回收机制
- 2018年上半年阅读总结(系统架构师)
- 手机开锁显示无法连接到服务器是什么问题,苹果手机连接服务器失败原因 苹果手机连接服务器失败是什么原因...
- html做表格(个人简历)
- WkwebView调节字体大小获取高度
- 计算机专业在职双证,计算机专业在职研究生可以获得在职研究生双证吗?
- 手机安装Linux系统(Ubuntu)
- 全球及中国便捷式GNSS接收器行业供应需求及项目投资战略分析报告2022-2027年
- FastReport安装方法精要
- 从“中国之光”到倒闭破产,北大方正做错了什么?
- Javscript数组中最常用的方法(建议收藏)
- 【Week14实验】猫睡觉问题【模拟】
热门文章
- 触发器及其应用实验报告总结_调机技巧总结: 先快后慢射胶法及其应用
- 看完后震惊!清华“姚班”创始人的老师究竟有多牛?他说孩子最应该培养这几个思维……...
- 神PS!老爸把儿子的画作P成现实,看完我笑哭了
- 批作业是小学老师的一大乐趣 | 今日最佳
- 和哪个专业的男生谈恋爱最惨?
- 分布式之数据库和缓存双写一致性方案解析!
- 桩筏有限元中的弹性板计算_永清县打桩机租赁钢板桩租赁怎么联系?
- oracle crontab e,Linux运维知识之通过crontab -e编辑生成的定时任务,写在哪个文件中...
- c语言中二重指针如何赋值,关于二重指针释放的有关问题
- 火柴人_火柴人 x THANKSGIVING