当前位置: 代码迷 >> 综合 >> 2018-1
  详细解决方案

2018-1

热度:138   发布时间:2023-10-14 06:31:13.0
/* 2020/4/16,机试二刷 */
#include<stdio.h>
#include<string.h>struct Line
{
    int sx,sy,ex,ey;int len;int flag;
}lines[100];int N;
int maxLen = 1;int main()
{
    int i,j,k;scanf("%d",&N);memset(lines,0,sizeof(lines));for(i = 0;i<N;i++){
    int sx,sy,ex,ey;scanf("%d%d%d%d",&sx,&sy,&ex,&ey);int L = 0,R = 0;for(j = 0;j<i;j++){
    if(lines[j].flag == 1 && lines[j].ex == sx && lines[j].ey == sy){
    L = 1;break;}}for(k = 0;k<i;k++){
    if(lines[k].flag == 1 && ex == lines[k].sx && ey == lines[k].sy){
    R = 1;break;}}if(L == 0 && R == 0){
    lines[i].sx = sx;lines[i].sy = sy;lines[i].ex = ex;lines[i].ey = ey;lines[i].len = 1;lines[i].flag = 1;}else if(L == 1 && R == 0){
    lines[j].ex = ex;lines[j].ey = ey;lines[j].len++;if(lines[j].len > maxLen)maxLen = lines[j].len;}else if(L == 0 && R == 1){
    lines[k].sx = sx;lines[k].sy = sy;lines[k].len++;if(lines[k].len > maxLen)maxLen = lines[j].len;}else{
    lines[j].ex = lines[k].ex;lines[j].ey = lines[k].ey;lines[j].len = lines[j].len + lines[k].len + 1;lines[k].flag = 0;if(lines[j].len > maxLen)maxLen = lines[j].len;}}for(i = 0;i<N;i++){
    if(lines[i].flag == 1 && lines[i].len == maxLen){
    printf("%d (%d,%d)\n",maxLen,lines[i].sx,lines[i].sy);break;}}return 0;
}
/* IN: 3 0 0 1 1 2 2 3 3 1 1 2 2 OUT: 3 (0,0) */
  相关解决方案