题目链接:http://codeforces.com/contest/416/problem/A
题目分析:夹逼法求y
代码:#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
#include<cmath>
using namespace std;
int main()
{
int n,x,l,r;
char tag[5],yn[5];
while(scanf("%d",&n)!=EOF)
{
r =2*1000000000;
l=-r;
for(int i=1; i<=n; i++)
{
scanf("%s%d%s",tag,&x,yn);
if(strcmp(tag,">=")==0)
{
if(yn[0]=='N')
{
if(x-1<r)
r=x-1;
}
else
{
if(x>l)
l=x;
}
}
else if(strcmp(tag,"<")==0)
{
if(yn[0]=='N')
{
if(x>l)
l=x;
}
else
{
if(x-1<r)
r=x-1;
}
}
else if(strcmp(tag,">")==0)
{
if(yn[0]=='N')
{
if(x<r)
r=x;
}
else
{
if(x+1>l)
l=x+1;
}
}
else if(strcmp(tag,"<=")==0)
{
if(yn[0]=='N')
{
if(x+1>l)
l=x+1;
}
else
{
if(x<r)
r=x;
}
}
}
if(l>r)
printf("Impossible\n");
else printf("%d\n",l);
}
return 0;
}
本文详细介绍了如何使用夹逼法解决Codeforces竞赛题416-A的问题,通过输入的数据,逐步计算并确定变量y的范围,最终输出可能的最小或最大值。
709

被折叠的 条评论
为什么被折叠?



