bnu A Matrix 北京邀请赛A题
A Matrix
- int f[][];
- int p[];
- int n;
- void insert(int r, int x)
- {
- for (int i=1; 1; i++)
- if (f[r][i]==0)
- {
- f[r][i]=x;
- return ;
- }
- else if (f[r][i]>x)
- {
- int tmp=f[r][i];
- f[r][i]=x;
- insert(r+1, tmp);
- return ;
- }
- }
- void Permutation2Matrix()
- {
- for (int i=1; i<=n; i++)
- insert(1, p[i]);
- }
Input
- First line contains 2 integers N (1 ≤ N ≤ 105), M (1 ≤ M ≤ N) indicating length of the permutation and number of rows which do not contains 0 in the matrix.
- Then M lines, the ith line represent the ith row in the matrix.
- The first integer in each line is Pi, indicating the number of non-zero elements in this row. Then Pi integers, indicating those elements.
Output
Sample Input
- 2
- 3 2
- 2 1 2
- 1 3
- 2 1
- 2 2 1
Sample Output
- Case #1: 1 3 2
- Case #2: No solution
Source

- #include<iostream>
- #include<stdio.h>
- #include<cstring>
- #include<cstdlib>
- #include<vector>
- using namespace std;
- vector<int>Q[];
- vector<int>Hash[];
- int hxl[],len;
- void dfs(int x,int y,int dep)
- {
- if(x>dep)return;
- if(Hash[x][y]==-)
- {
- Hash[x][y]=-;
- hxl[++len]=Q[x][y];
- return;
- }
- dfs(x+,Hash[x][y],dep);
- hxl[++len]=Q[x][y];
- Hash[x][y]=-;
- }
- void solve(int n,int m)
- {
- for(int i=m;i>=;i--)
- {
- int k=Hash[i][];
- int s=Hash[i-][];
- for(int j=k;j>=;j--)
- {
- for(;s>=;s--)
- if(Q[i][j]>Q[i-][s]){
- Hash[i-][s]=j;
- s--;
- break;
- }
- }
- }
- for(int i=;i<m;i++)
- {
- int num=;
- for(int j=;j<=Hash[i][];j++)
- if(Hash[i][j]!=-)num++;
- if(num!=Hash[i+][]){
- printf(" No solution\n");
- return;
- }
- }
- len = ;
- for(int i=;i<=m;i++)
- {
- for(int j=;j<=Q[i][];j++)
- {
- if(Hash[i][j]==-)hxl[++len]=Q[i][j];
- else if(Hash[i][j]==-)continue;
- else dfs(i,j,m);
- }
- }
- for(int i=;i<=len;i++)
- printf(" %d",hxl[i]);
- printf("\n");
- }
- int main()
- {
- int T,n,m,x,y;
- scanf("%d",&T);
- for(int t=;t<=T;t++)
- {
- scanf("%d%d",&n,&m);
- for(int i=;i<=n;i++){
- Q[i].clear();
- Hash[i].clear();
- }
- bool flag=false;
- for(int i=;i<=m;i++)
- {
- scanf("%d",&x);
- Q[i].push_back(x);
- Hash[i].push_back(x);
- for(int j=;j<=x;j++)
- {
- scanf("%d",&y);
- Q[i].push_back(y);
- Hash[i].push_back(-);
- if(j>&&Q[i][j]<=Q[i][j-]) flag=true;
- }
- if(i>&&Q[i][]>Q[i-][])flag=true;
- }
- printf("Case #%d:",t);
- if(flag==true)printf(" No solution\n");
- else{
- solve(n,m);
- }
- }
- return ;
- }
bnu A Matrix 北京邀请赛A题的更多相关文章
- BNUOJ 34985 Elegant String 2014北京邀请赛E题 矩阵快速幂
题目链接:http://acm.bnu.edu.cn/bnuoj/problem_show.php?pid=34985 题目大意:问n长度的串用0~k的数字去填,有多少个串保证任意子串中不包含0~k的 ...
- 2014 ACM/ICPC 北京邀请赛 部分 题解
题目链接:http://acm.bnu.edu.cn/bnuoj/problem.php?search=2014+ACM-ICPC+Beijing+Invitational+Programming+C ...
- hihocoder 1084 扩展KMP && 2014 北京邀请赛 Justice String
hihocoder 1084 : http://hihocoder.com/problemset/problem/1084 北京邀请赛 Just String http://www.bnuoj.co ...
- 2013长沙网络赛H题Hypersphere (蛋疼的题目 神似邀请赛A题)
Hypersphere Time Limit: 1 Second Memory Limit: 32768 KB In the world of k-dimension, there's a ...
- 2013 ACM/ICPC南京邀请赛B题(求割点扩展)
题目链接:http://icpc.njust.edu.cn/Contest/194/Problem/B B - TWO NODES 时间限制: 10000 MS 内存限制: 65535 KB 问题描述 ...
- XTU 1264 - Partial Sum - [2017湘潭邀请赛E题(江苏省赛)]
2017江苏省赛的E题,当时在场上看错了题目没做出来,现在补一下…… 题目链接:http://202.197.224.59/OnlineJudge2/index.php/Problem/read/id ...
- bnu 29378 Adidas vs Adivon 基础题
Adidas vs Adivon Time Limit: 1000ms Memory Limit: 65536KB 64-bit integer IO format: %lld Java ...
- 2013 南京邀请赛 K题 yet another end of the world
/** 大意:给定一组x[],y[],z[] 确定有没有两个不同的x[i], x[j] 看是否存在一个ID使得 y[i]<=ID%x[i]<=z[i] y[j]<=ID%x[j]&l ...
- 2014 北京邀请赛ABDHJ题解
A. A Matrix 点击打开链接 构造,结论是从第一行開始往下产生一条曲线,使得这条区间最长且从上到下递减, #include <cstdio> #include <cstrin ...
随机推荐
- 转:windows 7系统安装与配置Tomcat服务器环境
工具/原料 jdk-7u45-windows-x64(我的系统是64位系统,32位的请选x86下载) apache-tomcat-8.0.0-RC5-windows-x64 方法/步骤 下载说明, ...
- SQL 存储和触发器
存储过程:就像函数一样的会保存在数据库中-->可编程性 --> 存储过程 创建存储过程:create proc JiaFa--需要的参数@a int,@b intas --存储过程的内容 ...
- 面向切面编程AOP:基于注解的配置
Aop编程就是面向编程的羝是切面,而切面是模块化横切关注点. -切面:横切关注点,被模块化的特殊对象. -通知:切面必须要完成的工作 -目标:被通知的对象 -代理:向目标对象应用通知之后创建的对象. ...
- 杭电ACM分类
杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...
- sql字符转换函数大全
删除空格 有两个函数,TTRIM()和LTRIM(),可以用来从字符串中剪掉空格.函数LTRIM()去除应该字符串前面的所有空格:函数RTRIM()去除一个字符串尾部的所有空格.这些和vbscript ...
- II7下配置SSAS通过HTTP 远程链接访问
IIS7下配置SSAS通过HTTP远程连接 安装环境操作系统:Windows7.Windows Server2008IIS版本:7.5 IIS7下配置SSAS通过HTTP远程连接详细的步骤如下:1.首 ...
- C#访问postgresql数据库
最近开始做C#的DotNet的工作,因为对PostgreSQL数据库比较有兴趣,所以自己研究了一下如何访问PostgreSQL的 数据库的问题. 1.为了访问PostgreSQL数据库,需要从pgfo ...
- 夺命雷公狗---node.js---10之POST的接收
首先我们在项目下创建一个表单,代码如下所示: <!DOCTYPE html> <html lang="en"> <head> <meta ...
- html规范整体结构
<!DOCTYPE html><html lang="zh"><head> <meta charset="utf-8" ...
- Date() 及其 如何验证用户输入的日期是合法的
1.var someDate = new Date(Date.parse("May 25, 2004")); <=> var someDate = new Dat ...