玲珑OJ 1097
来源:互联网 发布:js判断字符串不等于 编辑:程序博客网 时间:2024/04/28 22:08
1097 - 萌萌哒的第二题Time Limit:5s Memory Limit:128MByteSubmissions:610Solved:155DESCRIPTION一条东西走向的河两边有都排着工厂,北边有n间工厂A提供原材料,南边有n间工厂B进行生产。现在需要在工厂A和工厂B之间建运输桥以减少运输成本。可是每个工厂B只能接受最多6个工厂A提供的材料能满足生产,而且建立的运输桥之间不能有交叉,北边的工厂A由西向东编号1~n,南边的工厂B也是一样,不能交叉的意思是如果a号工厂A跟b号工厂B之间建立了运输桥,那么不能存在c、d(c < a 且d > b) 使得c号工厂A和d号工厂b之间建立运输桥,每个工厂A只能给一个工厂B提供材料,每个工厂B只能由一间工厂A提供材料,请问在满足上述条件的情况下最多能建立多少个运输桥。(每个工厂最多有6个选择,但只能选一个)INPUT包含多组测试数据(<=15),其中每组测试数据: 第一行一个整数n(1<= n <= 10^5) 接下来n行,第i+1行6个整数表示i号工厂B能接受的6个工厂A的编号,保证所有编号的范围是1~n,可能重复(请看样例)。OUTPUT每组数据输出一行一个整数表示最多能建立的运输桥数量。SAMPLE INPUT31 2 3 1 2 32 2 2 2 2 21 3 1 3 1 361 2 3 4 5 61 2 3 4 5 61 2 3 4 5 61 2 3 4 5 61 2 3 4 5 61 1 1 1 1 1SAMPLE OUTPUT35SOLUTION“玲珑杯”ACM比赛 Round #11
很容易就想到dp O(n^2) 复杂度太高
万万没想到 这居然是LIS
因为每个B只能选6个A
将每个B的6个选择按从大到小排序 然后求最长单增子序列即可
例如样例一
【1 2 3 1 2 3】,【2 2 2 2 2 2】,【1 3 1 3 1 3】——>332211 222222 333111
LIS=123
#include<iostream>#include<stdlib.h>#include<stdio.h>#include<string>#include<vector>#include<deque>#include<queue>#include<algorithm>#include<set>#include<map>#include<stack>#include<time.h>#include<math.h>#include<list>#include<cstring>#include<fstream>#include<queue>#include<sstream>//#include<memory.h>using namespace std;#define ll long long#define ull unsigned long long#define pii pair<int,int>#define INF 1000000007#define pll pair<ll,ll>#define pid pair<int,double>const int inf=1e9+7;const int N = 1e5+5;int a[6*N];int len=0;int lis[6*N];int LIS(int*a,int len){ int size=0; for(int i=0;i<len;++i){ int x=a[i]; int*p=lower_bound(lis,lis+size,x); if(p!=lis+size){ *p=x; } else{ lis[size++]=x; } } return size;}int main(){ //freopen("/home/lu/Documents/r.txt","r",stdin); //freopen("/home/lu/Documents/w.txt","w",stdout); int n; int t[6]; while(~scanf("%d",&n)){ len=0; for(int i=0;i<n;++i){ for(int j=0;j<6;++j){ scanf("%d",&t[j]); } sort(t,t+6,greater<int>()); for(int j=0;j<6;++j){ if(len!=0&&a[len-1]==t[j]){ continue; } a[len++]=t[j]; } } printf("%d\n",LIS(a,len)); } return 0;}
0 0
- 玲珑OJ 1097
- 玲珑oj 1097
- SDUT oj 玲珑龟
- 玲珑oj 1074
- 玲珑oj 1072 - Capture
- 玲珑oj Digital Count
- 玲珑OJ 1047
- 玲珑oj 1096
- 玲珑oj 1099
- 玲珑OJ 1100
- 玲珑OJ-1100
- 玲珑学院OJ 1126
- 玲珑学院OJ 1125
- 玲珑学院OJ 1131
- 玲珑oj 1125
- 玲珑oj 1129
- 玲珑oj 1067
- 玲珑学院OJ 1121
- ettercap,shank和bettercap利用BeEF进行中间人攻击(1)
- 215. Kth Largest Element in an Array
- TCP和UDP的区别
- 小白的windows cpu 下caffe学习笔记(1)mnist测试
- java this的关键字
- 玲珑OJ 1097
- 例子讲解Vue.js的slot分发
- CodeForces
- Hadoop之Text与String的异同
- 2016年腾讯笔试题——构造回文
- 【BOI2012】Mobile(mobile)
- Hibernate执行流程和关系映射
- java打印99乘法表,双重for循环
- LeetCode : Intersection of Two Arrays II