2010年山东省第一届ACM解SDUT2151-2160 set,floyd变形
2016-04-09 19:47
381 查看
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; }
相关文章推荐
- 汉诺塔递归算法
- Whu oj 1609 - Han Move
- 软件工程结对作业02(借鉴版)
- JavaScript编写人机对战五子棋(七)
- mysql.bat
- 栈面试题
- 第七周项目1-点类-成员函数
- Linux下硬链接和软链接
- 如何在博客园发博客时插入优酷视频
- Java-Eclipse编辑窗口不见了
- 嵌入式linux常用shell指令
- Androdi AsyncTask
- 软件工程结对作业02(原创版)
- iOS开发学习之 - 深入学习UIButton(2)
- 《leetCode》:Kth Largest Element in an Array
- c++模板实现队列
- Collection集合层次结构图
- Whu oj 1606 - Funny Sheep
- leetcode 58. Length of Last Word
- 更新到Xcode 7.3 #import 不提示的问题