POJ - 4044 Score Sequence 模拟+贪心
题目链接:点击查看
题意:给出两个班级的成绩,先按降序排序,去重。然后求连续的最长公共子序列。输出时,先输出最长公共子序列,然后按个位数字递增的顺序输出,若各位数字一样就按成绩递增。
题解:模拟写就可以了
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=110;
int n1,n2;
int a[N],b[N],c[N],len;
bool cmp1(int x,int y)
{return x>y;
}
bool cmp2(int x,int y)
{if(x%10!=y%10) return x%10<y%10;else return x<y;
}
int main()
{int T;scanf("%d",&T);while(T--){scanf("%d%d",&n1,&n2);for(int i=1;i<=n1;i++)scanf("%d",&a[i]);for(int j=1;j<=n2;j++)scanf("%d",&b[j]);int i=1,j=1;int pos,ans=0,cnt=0;sort(a+1,a+1+n1);sort(b+1,b+1+n2);n1=unique(a+1,a+1+n1)-(a+1);n2=unique(b+1,b+1+n2)-(b+1);while(i<=n1&&j<=n2){if(a[i]==b[j]){cnt++;i++;j++;}else if(a[i]>b[j]){if(cnt>=ans){ans=cnt;pos=i-1;}cnt=0;j++;}else{if(cnt>=ans){ans=cnt;pos=i-1;}cnt=0;i++;}}if(cnt>=ans){ans=cnt;pos=i-1;}if(ans==0) printf("NONE\n");else{len=0;for(int i=pos-ans+1;i<=pos;i++)c[++len]=a[i];sort(c+1,c+1+len,cmp1);for(int i=1;i<=len;i++)printf("%d%c",c[i]," \n"[i==len]);sort(c+1,c+1+len,cmp2);for(int i=1;i<=len;i++)printf("%d%c",c[i]," \n"[i==len]);}}return 0;
}
相关文章:

POJ - 4045 Power Station 树形dp
题目链接:点击查看 题意:n个城市节点构成的一棵树,节点i到节点j的电量损耗为 I*I*R*(i到j的路径所含边数),现在要在某个结点上修建一个供电站,使得这个结点到所有其它节点的总损耗量最小。 题解:I*I*R可以…...

POJ - 4048 Chinese Repeating Crossbow 暴力枚举+线段香蕉?
题目链接:点击查看 题意:从一给出的点出发可以向任意方向发出射线,然后现在平面上共有1500条线段,问最多能使射线和几条线段相交 题解:每个线段都有一个对应的角度范围,刚开始想的是离散化一下࿰…...

POJ - 4047 Garden 线段树 区间更新
题目链接:点击查看 题意: 给出一个N个数的序列以及一个k(0<k<n<200000),m个操作p,x,y,其中 p0:将x位置的数替换为y p1:将x y位置的数互换 p2: 查询x-y位置区间连续k个数的和的最…...

POJ - 4046 Sightseeing 暴力枚举下的SPFA
题目链接:点击查看 题意:给一个图和q个询问,每个询问查询图中两点的(距离路径上最大值)的最小值。 题解:暴力枚举每个点,以这个点为起点并且为路径上所有经过的点的价值中最大的点来跑最短路&…...

CCPC-Wannafly Winter Camp Day5 (Div2, onsite)
题目链接:点击查看 Kropki: 题目描述: 你有一个11到nn的排列p_1, p_2, \dots, p_np1,p2,…,pn,对于所有的i (1\leq i\leq n-1)i(1≤i≤n−1),如果p_ipi和p_{i1}pi1中,有一个数是另一个的两倍&…...

HDU - 4389 X mod f(x) 数位dp
题目链接:点击查看Here is a function f(x):int f ( int x ) {if ( x 0 ) return 0;return f ( x / 10 ) x % 10;}Now, you want to know, in a given interval [A, B] (1 < A < B < 10 9), how many integer x that mod f(x) equal to 0. Input The fi…...

牛客网 Applese 走方格
题目链接:点击查看 题解:我们容易发现到当n,m都为奇数时,是回不到原点的,因为你无论哪个方向走一去一回就是两步,所以n和m必然有一个偶数,那至于我们怎么走呢,看下图,注意的是n1,m2…...

Manacher 马拉车算法 hdu3068 最长回文
算法讲解:点击查看 核心代码:p[i] maxx > i ? min ( p[id - ( i - id ) ] , maxx - i ) : 1 ; 给出一个只由小写英文字符a,b,c...y,z组成的字符串S,求S中最长回文串的长度. 回文就是正反读都是一样的字符串,如aba, abba等 Input 输入有多组case…...

Manacher 马拉车算法 吉哥系列故事——完美队形II HDU - 4513
吉哥又想出了一个新的完美队形游戏! 假设有n个人按顺序站在他的面前,他们的身高分别是h[1], h[2] ... h[n],吉哥希望从中挑出一些人,让这些人形成一个新的队形,新的队形若满足以下三点要求,则就是新的…...

马拉车算法 Palindrome POJ - 3974
马拉车算法 推荐博客:点击查看 Andy the smart computer science student was attending an algorithms class when the professor asked the students a simple question, "Can you propose an efficient algorithm to find the length of the largest palin…...

HDU - 1358 Period kmp next数组求循环节
题目链接:点击查看 For each prefix of a given string S with N characters (each character has an ASCII code between 97 and 126, inclusive), we want to know whether the prefix is a periodic string. That is, for each i (2 < i < N) we want to …...
HDU - 3746 Cyclic Nacklace next数组求 循环节
题目链接:点击查看 CC always becomes very depressed at the end of this month, he has checked his credit card yesterday, without any surprise, there are only 99.9 yuan left. he is too distressed and thinking about how to tide over the last days. …...

POJ - 2406 Power Strings next数组应用循环节
题目链接:点击查看 Language:Default Power Strings Time Limit: 3000MS Memory Limit: 65536KTotal Submissions: 61784 Accepted: 25534Description Given two strings a and b we define a*b to be their concatenation. For example, if a "abc" and…...

POJ - 2752 Seek the Name, Seek the Fame next数组应用
题目链接:点击查看 The little cat is so famous, that many couples tramp over hill and dale to Byteland, and asked the little cat to give names to their newly-born babies. They seek the name, and at the same time seek the fame. In order to escape…...

HDU - 3336 Count the string dp+kmp
题目链接:点击查看 It is well known that AekdyCoin is good at string problems as well as number theory problems. When given a string s, we can write down all the non-empty prefixes of this string. For example: s: "abab" The prefixes …...

后缀数组 Distinct Substrings SPOJ - DISUBSTR /New Distinct Substrings SPOJ - SUBST1
后缀数组-处理字符串的有力工具 : 点击查看 后缀数组模板及代码详解:点击查看 Given a string, we need to find the total number of its distinct substrings. Input T- number of test cases. T<20; Each test case consists of one string, who…...

EOJ Monthly 2019.2 (based on February Selection)
题目链接:点击查看 A. 回收卫星 单测试点时限: 1.0 秒 内存限制: 256 MB “这个世上没有无用的齿轮,也只有齿轮本身能决定自己的用途。” 就像太空中的卫星,虽然不计其数,但都各司其职。 但没有一个东西是能够永远无损的。为…...

CodeForces1131 D. Gourmet choice 并查集+拓扑排序
题目连接:点击查看 Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of rev…...

CodeForces1131 F. Asya And Kittens 并查集
题目连接:点击查看 output standard output Asya loves animals very much. Recently, she purchased n kittens, enumerated them from 1 and n and then put them into the cage. The cage consists of one row of n cells, enumerated with integers from 1 …...

CodeForces - 545B Equidistant String 构造
题目链接:点击查看 Little Susie loves strings. Today she calculates distances between them. As Susie is a small girl after all, her strings contain only digits zero and one. She uses the definition of Hamming distance: We will define the distan…...

CodeForces - 545C Woodcutters dp
题目链接:点击查看 Little Susie listens to fairy tales before bed every day. Todays fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described below…...

CodeForces - 545D Queue 贪心 排序
题目链接:点击查看 Little girl Susie went shopping with her mom and she wondered how to improve service quality. There are n people in the queue. For each person we know time ti needed to serve him. A person will be disappointed if the time he …...

CodeForces - 545E Paths and Trees 最短路建树
题目链接:点击查看 Little girl Susie accidentally found her elder brothers notebook. She has many things to do, more important than solving problems, but she found this problem too interesting, so she wanted to know its solution and decided to a…...

CodeForces - 545A Toy Cars 水题
题目链接:点击查看 Little Susie, thanks to her older brother, likes to play with cars. Today she decided to set up a tournament between them. The process of a tournament is described in the next paragraph. There are n toy cars. Each pair collid…...
POJ - 1451 T9 字典树
题目连接:点击查看 Background A while ago it was quite cumbersome to create a message for the Short Message Service (SMS) on a mobile phone. This was because you only have nine keys and the alphabet has more than nine letters, so most character…...

HDU - 2328 Corporate Identity / POJ - 3080 Blue Jeans kmp 枚举
题目连接:点击查看 题意:n个字符串最长公共子串,相同长度就找字典序小的,poj那个是长度小于3,输出那句话 题解:以某一字符串为基准,枚举每个子串,然后暴力kmp即可,特记…...

CodeForces - 555A Case of Matryoshkas
题目链接:点击查看 题意:太他妈难懂了,大致意思就是有k条链,想得到1->2->..>n,这样的链,有两种操作,一种是断开链,需要1秒,一种是可以将1个单独的数字接在链后…...

CodeForces - 557C Arthur and Table 预处理 前缀
题目链接:点击查看 题意:有n个桌腿,要砍掉某些桌腿,使剩下的桌腿中长度最大的桌腿的数量如果超过一半。砍掉每个桌腿需要付出代价。求最小的代价和,操蛋,砍掉的意思是直接去掉,我理解成了&…...

CodeForces - 558C Amr and Chemistry 二进制标记
题目链接:点击查看 题意:n个数字,可以乘以2,可以除以2,问总共多少次运算,使n个数一样 题解:因为是*2 /2 运算 数最大为1e5,每个数运算最多400次作左右,我们就暴力把每个…...

CodeForces - 555C Case of Chocolate set pair
题目链接:点击查看 题意:有一个n*n的矩形,给你对角线上的坐标,给你一个方向,问能走几个坐标,遇到之前已经经过的坐标就停止 题解:当给你一个坐标(x,y),方向向上时,他能…...

ZOJ - 2968 Difference Game 思维
题目链接:点击查看 Now you are going to play an interesting game. In this game, you are given two groups of distinct integers and C coins. The two groups, named Ga and Gbrespectively, are not empty and contain the same number of integers at firs…...

HDU - 3971 Play With Sequence 线段树 权值范围修改
题目链接:点击查看 When the girl was solving GSSX, a serious of tough problems about data structure on SPOJ, something intriguing once again comes to GYZs mind. That is, for a changing sequences, how to count how many elements in a specific rang…...

ZOJ - 3204 Connect them 最小生成树
题目链接:点击查看 You have n computers numbered from 1 to n and you want to connect them to make a small local area network (LAN). All connections are two-way (that is connecting computers i and j is the same as connecting computers j and i). T…...
ZOJ - 3209 Treasure Map 暴搜
题目链接:点击查看 Your boss once had got many copies of a treasure map. Unfortunately, all the copies are now broken to many rectangular pieces, and what make it worse, he has lost some of the pieces. Luckily, it is possible to figure out the p…...

tarjan算法讲解
由于本人实在太菜,某题自己瞎鸡巴写实在写不出来了,就学一下tarjan算法了。 算法介绍来自某位15级学长,点击查看:点击查看 核心代码: void targan(int u) {dfn[u]low[u]tot;sta[len]u;vis[u]1;for(int i0;i<v[u]…...

HDU - 5934 Bomb tarjan缩点
题目链接:点击查看 题意:有N个炸弹,每个炸弹有一个坐标,一个爆炸范围和一个爆炸花费,如果一个炸弹的爆炸范围内有另外的炸弹,那么如果该炸弹爆炸,就会引爆所有爆炸范围内的炸弹,求让…...

HDU - 5934 Bomb 前后dp
题目链接:点击查看 题意:Bessie和Elsie在玩一种卡牌游戏。一共有2N张卡牌,点数分别为1到2N,每头牛都会分到N张卡牌。游戏一共分为N轮,因为Bessie太聪明了,她甚至可以预测出每回合Elsie会出什么牌。每轮游戏…...

HDU - 5943 Kingdom of Obsession 二分匹配
题目链接:点击查看 题意:给你s,n,要求给s1,s2...sn,这n个数编号1-n,满足每个数膜编号为0,问是否存在 题解:打表发现两个素数的差值不足300,我们可以发现素数的因子只有…...

树上倍增
文字转自:点击查看 倍增比起树链剖分,代码短,容易查错,时空复杂度也优很多(nlogn),只是功能有些欠缺。 倍增的思想是二进制。 首先开一个nlogn的数组,比如f[n][logn],其中…...

POJ - 1330 Nearest Common Ancestors LCA-树上倍增
题目链接:点击查看 题意:求最近公共祖先 题解:树上倍增模板->点击查看 #include <iostream> #include <cstdio> #include <vector> #include <algorithm> #include <cmath> using namespace std; const …...

POJ - 3107 Godfather 树的重心
题目链接:点击查看 题意:找出树的重心,如果多个按编号从小到大输出 树的重心定义:点击查看 题解:树形dp,找出孩子中最大的,n-孩子总数即为向上节点数,求个最大的即可 #include&…...

HDU - 4352 XHXJ's LIS 数位dp 二进制存状态 LIS
题目链接:点击查看 题意:l - r 中有多少 最长上升序列为k的个数 不要求连续 题解:因为这个k并不大,所以我们可以想到用二进制来储存,我们再求一般的最长上升子序列时,是先保存在一个数组中,…...

HDU - 5091 Beam Cannon 线段树 扫描线
题目链接:点击查看 题意:给你n个点的坐标,给你一个矩形的w,h,问最多能圈住多少点 题解:扫描线,按x轴进行扫描,其实就是把一个点的左右范围找出来,一个为正,…...

HDU - 5092 Seam Carving dp 标记路径
题目链接:点击查看 题意:给你n*m的矩阵,求从第一行到第n行值加起来的最小路径,(i,j)可以走向(i1,j-1) (i1,j) (i1,j1) ,尽可能向右走 题解:dp一遍即可,尽量取右边的 #include<bits/stdc.h…...

HDU - 5093 Battle ships 二分匹配 + 建图
题目链接:点击查看 题意:n*m的海洋,o是薄冰,#是冰面,*是海洋,问最多能放多少船,不能同行同列,除非他们之间有冰面(#) 题解:二分匹配,…...

SPOJ - QTREE2 Query on a tree II 树上倍增+LCA
题目链接:点击查看 题意:给你一棵树,DIST a b 查询a到b的距离,KTH a b c 查询a到b的路径上第c个点是啥 题解:树上倍增,先预处理每个dp[u][i],查询a,b距离时,设他们的最…...

HYSBZ - 3813 奇数国 线段树区间维护+欧拉
题目链接:点击查看 题意:长度100000的序列,原始都为3,两个操作,1 a b 把p[a] 改为b,0 a b 把[a,b] 区间数相乘,求这个数的欧拉值 题解:因为每个数都可以通过前60个素数表示&#x…...

HDU - 3980 Paint Chain sg打表
题目链接:点击查看 题意:有一个带有n个珠子的圆链,起初圆链上的珠子都未被染色。规定两人轮流染色,每人每次只能挑选m个连续的未被染色的珠子进行染色,Aekdycoin先来,最后谁先不能染色谁则输掉了这场比赛&…...
HDU - 1943 Ball bearings 计算几何
题目链接:点击查看 题意:现在给出一个大圆圈,然后在大圆圈里面要放多个小圆圈,且要求所有的小圆圈必须与大圆圈的内表面相切,两个小圆圈之间的距离要大于等于给定值s。 题解:取两个相邻的小圆,…...

HYSBZ - 2342 双倍回文 马拉车算法
题目链接:点击查看 题意:找一个回文串,他的一半也是回文串,并且长度是4的倍数 题解:马拉车算法跑一遍,记录每一个r[i]值,在判断左半部分的是否符合条件,负责度? #incl…...