2016百度之星资格赛E题
2016-05-15 15:14
281 查看
Problem E
Accepts: 129Submissions: 629
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 65536/65536 K (Java/Others)
Problem Description
小度熊是一个尽职尽责的程序熊,每天产出数千行的代码,代码当中存在很多判断条件。度熊想让自己代码中的这些条件不存在交集。为了简化问题,一个条件可以是一个『简单条件』或者是一个『复合条件』,简单条件由『变量』、『比较符』和『运算数』组成,其中『变量』是用小写字符表示的一串字符,『运算数』仅为整数,『运算符』包括:<、>、<=、>=、==。分别代表:小于、大于、小于等于、大于等于和等于关系。简单条件的格式固定,左边为变量名,中间为操作符,右边为数字。若干个『简单条件』中间通过英文逗号组成一个『复合条件』,各『简单条件』之间是逻辑与的关系,例如:
简单条件: a > 100 复合条件: duxiong < 1000 , a > 100
Input
这里包括一组测试数据,第一行一个正整数 N(1≤N≤1000),接下来
N
行,每行一个条件,条件可能是一个『简单条件』或者是一个『复合条件』。其中『变量』不会超过30个字符,『运算数』的绝对值在10,000以内。测试数据中,不同变量的数量不会超过30个。其中『变量』、『比较符』和『运算数』之前和之后都有可能出现若干空格字符。所有简单规则都是按照『变量』『比较符』『运算数』这样的顺序定义的,没有特例。
Output
对于第 i
个条件,输出其与前 i−1个条件是否存在交集非空的情况。如果不存在交集非空的其他条件,输出一行字符串:『unique』。否则按照从小到大的顺序输出与其存在非空交集的条件的编号,编号之间用空格分隔,最后一个编号末尾不加空格。各条件从1−N编号。
Sample Input
Copy
4 a < 100 c > 99 b > 100 , b == 99 , c < 98 a < 1000, a >= 99
Sample Output
Copy
unique 1 unique 1 2
http://bestcoder.hdu.edu.cn/contests/contest_showproblem.php?cid=690&pid=1005
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define inf 10010
struct hi
{
int flag;
int count;
char one[40][40];
int two1[40],two2[40];
int three[40];
hi()
{
flag=0;
count=0;
for(int i=1;i<=35;i++)
{
two1[i]=-inf;
two2[i]=inf;
}
}
}a[1010];
void Union(char temp2[40],int temp4,int i,int x)
{
if(strcmp(temp2,"==")==0)
{
if(temp4>=a[x].two1[i] && temp4<=a[x].two2[i])
a[x].two1[i]=a[x].two2[i]=temp4;
else
a[x].flag=1;
}
else if(strcmp(temp2,">")==0)
{
temp4++;
if(temp4>=a[x].two1[i] && temp4<=a[x].two2[i])
a[x].two1[i]=temp4;
else if(temp4<a[x].two1[i]);
else
a[x].flag=1;
}
else if(strcmp(temp2,">=")==0)
{
if(temp4>=a[x].two1[i] && temp4<=a[x].two2[i])
a[x].two1[i]=temp4;
else if(temp4<a[x].two1[i]);
else
a[x].flag=1;
}
else if(strcmp(temp2,"<")==0)
{
temp4--;
if(temp4>=a[x].two1[i] && temp4<=a[x].two2[i])
a[x].two2[i]=temp4;
else if(temp4>a[x].two2[i]);
else
a[x].flag=1;
}
else
{
if(temp4>=a[x].two1[i] && temp4<=a[x].two2[i])
a[x].two2[i]=temp4;
else if(temp4>a[x].two2[i]);
else
a[x].flag=1;
}
}
void deal(char temp1[40],char temp2[40],char temp3[40],int x,int num)
{
int len=strlen(temp3),i;
int temp4=0;
i=0;
if(temp3[0]=='-')
i=1;
for(;i<len;i++)
temp4=10*temp4+temp3[i]-'0';
if(temp3[0]=='-')
temp4*=-1;
for(i=1;i<=num;i++)
if(strcmp(a[x].one[i],temp1)==0)
{
Union(temp2,temp4,i,x);
break;
}
if(i==num+1)
{
a[x].count++;
strcpy(a[x].one[i],temp1);
Union(temp2,temp4,i,x);
}
}
void ans(int x)
{
int arg[1010],l=0,sign;
if(a[x].flag==1)
{
printf("unique\n");
return;
}
for(int i=1;i<x;i++)
{
sign=0;
if(a[i].flag==1)
continue;
for(int j=1;j<=a[x].count;j++)
{
for(int k=1;k<=a[i].count;k++)
if(strcmp(a[x].one[j],a[i].one[k])==0)
if(a[x].two2[j]<a[i].two1[k] || a[i].two2[k]<a[x].two1[j])
{
sign=1;
break;
}
if(sign==1)
break;
}
if(sign==0)
arg[l++]=i;
}
if(l==0)
{
printf("unique\n");
return;
}
else
{
for(int i=0;i<l;i++)
if(i==l-1)
printf("%d\n",arg[i]);
else
printf("%d ",arg[i]);
}
}
int main()
{
int n,where;
char b[300],temp1[40],temp2[40],temp3[40];
cin>>n;
getchar();
for(int i=1;i<=n;i++)
{
gets(b);
where=0;
int len=strlen(b);
for(int j=0;j<len;)
{
if(b[j]==' ' || b[j]==',')
{
j++;
continue;
}
if(where==0)
{
int k=0;
while(j<len && b[j]!=' ' && b[j]!=',')
temp1[k++]=b[j++];
temp1[k]='\0';
where=1;
}
else if(where==1)
{
int k=0;
while(j<len && b[j]!=' ' && b[j]!=',')
temp2[k++]=b[j++];
temp2[k]=0;
where=2;
}
else
{
int k=0;
while(j<len && b[j]!=' ' && b[j]!=',')
temp3[k++]=b[j++];
temp3[k]=0;
where=0;
if(a[i].flag==0)
deal(temp1,temp2,temp3,i,a[i].count);
}
}
ans(i);
}
return 0;
}
相关文章推荐
- 小团队,个人任务没完成导致团队加班是否应该赞赏?
- 如何实现鼠标悬停图片放大的效果。
- TextView
- Problem J: Arithmetic Sequence——华中农业大学第四届程序设计大赛网络同步赛题目
- 蒙特卡洛采样之拒绝采样(Reject Sampling)
- 关于孔乐器
- 什么是Dubbo
- android layout 的小知识
- Lock的使用
- Docker学习系列(二):Ubuntu下安装Docker
- 【新手入门】C++中的一点问题
- 指南针的实现代码两种方法,怎么用
- mockito-ArgumentMatcher
- 1、oracle后台进程(数据字典V$BGPROCESS)
- 前后端数据交互方法
- 数值的整数次方
- Linux C下进程操作实例
- linux企业常用服务---squit传统代理
- 【Android】图像增强
- mockito-ArgumentCaptor