2010年山东省第一届ACM解SDUT2151-2160 set,floyd变形

Ivan comes again!

矩阵中有N个被标记的元素,然后针对每一个被标记的元素e(x,y),你要在所有被标记的元素中找到一个元素E(X,Y),使得X>x并且Y>y,如果存在多个满足条件的元素,先比较X,选择X最小的那个,如果还是有很多满足条件的元素,再比较Y,选择Y最小的元素,如果不存在就输出两个-1;

本题感悟
///比赛时出错的地方  检查代码的错误要从头开始检查,捋清楚思路再敲
///1.运算符号重载x,y写错了(SB了)
///2. 还有就是题目是让输出一个值的我输出了所有的至出来了
///(没有看题就直接敲的结果,以后听完题意之后要大体的看一下)

#include<bits/stdc++.h>
using namespace std;
struct node
{
	int x,y;
	friend bool operator <(node a,node b)
	{
		if(a.x==b.x) return a.y<b.y;           
		return a.x<b.x;
	}
};
char s[1000];
int main()
{
	int n,cas=1,a,b;
	node q;
	while(~scanf("%d",&n),n)
	{
		set<node> p;
		set<node> ::iterator it1;
		printf("Case %d:\n",cas++);
		for(int i=1;i<=n;i++)
		{
			scanf("%s%d%d",s,&q.x,&q.y);
			if(s[0]=='a')
				p.insert(q);

			else if(s[0]=='r')
				p.erase(q);

			else
			{
				it1=p.lower_bound(q);
				for(it1;it1!=p.end();it1++)
				{
					if(it1->x>q.x && it1->y>q.y)
                    {
                        printf("%d %d\n",it1->x,it1->y);
						  break;
                    }
				}
				if(it1==p.end())
				{
					printf("-1\n");
				}
			}
		}
		printf("\n");

	}
	return 0;
}
//#include<bits/stdc++.h>
//using namespace std;
//
//char s[1000];
//int main()
//{
//	int n,cas=1,a,b;
//
//	while(~scanf("%d",&n),n)
//	{
//		set<pair<int,int> >p;
//		pair<int,int>q;
//		set<pair<int,int> > ::iterator it1;
//		printf("Case %d:\n",cas++);
//		for(int i=1;i<=n;i++)
//		{
//			scanf("%s%d%d",s,&q.first,&q.second);
//			if(s[0]=='a')
//				p.insert(q);
//
//			else if(s[0]=='r')
//				p.erase(q);
//
//			else
//			{
//				it1=p.lower_bound(q);
//             ///   if(it1==p.end()) it1=p.begin();
//				for(it1;it1!=p.end();it1++)
//				{
//					if(it1->first>q.first && it1->second>q.second)
//                    {
//                        printf("%d %d\n",it1->first,it1->second);
//						  break;
//                    }
//				}
//				if(it1==p.end())
//				{
//					printf("-1\n");
//				}
//			}
//		}
//		printf("\n");
//
//	}
//	return 0;
//}

还有离散化线段树的敲法待整理

<span style="font-size:18px;">图论floyd变形
SDUT 2155</span>


#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;
int vis[1000];
int Map[1000][1000];
int main()
{
    int n,m,q;
    int u,v,t,x,cas=1;
    while(~scanf("%d%d%d",&n,&m,&q),n+m+q)
    {
        memset(Map,INF,sizeof(Map));
        printf("Case %d:\n",cas++);
        for(int i=0; i<=n; i++)
            Map[i][i]=0;
        for(int i=1; i<=m; i++)
        {
            scanf("%d%d%d",&u,&v,&t);
            Map[u][v]=min(Map[u][v],t);
        }
        memset(vis,0,sizeof(vis));
        while(q--)
        {
            scanf("%d",&t);
            if(t==0)
            {
                scanf("%d",&x);
                if(vis[x])
                    printf("City %d is already recaptured.\n",x);
                else
                {
                    vis[x]=1;                   ///新插入的点
                    for(int i=0; i<n; i++)
                    {
                        for(int j=0; j<n; j++)
                        {
                            if(Map[i][j]>Map[i][x]+Map[x][j])   ///更新i与j之间的距离
                                Map[i][j]=Map[i][x]+Map[x][j];
                        }
                    }
                }

            }
            else
            {
                scanf("%d%d",&u,&v);
                if(!vis[u]||!vis[v])
                    printf("City %d or %d is not available.\n",u,v);
                else
                {
                    {
                        if(Map[u][v]==INF)
                            printf("No such path.\n");
                        else
                            printf("%d\n",Map[u][v]);
                    }
                }

            }
        }
        printf("\n");
    }
    return 0;
}
 



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值