Problem J: Train Tracks

Andy loves his set of wooden trains and railroad tracks. Each day, Daddy has to build a new track for him. The tracks he likes best form a simple loop with no branches or dead ends, so he can run his trains around and around for hours until it is time for the big crash that destroys the whole construction.

So here is the question: Given a set of track pieces, can you form a simple loop with them, while using up all the pieces?

Each piece of track is described by the connectors at both ends. A standard piece has one "male" and one "female" connector. But there are also track pieces with two male or two female connectors, as shown in the front right of the picture.

To fit together, each male connector must be connected to a female connector. Unlike real wooden tracks, our pieces are assumed to be flexible, so their length or shape is not an issue here. However, you may not connect the two ends of the same piece together.

Input begins with the number of test cases. Each following line contains one test case. Each test case consists of a list of between 1 and 50 (inclusive) train track pieces. A piece is described by two code letters: M for male or F for female connector. Pieces are separated by space characters.

For each test case, output a line containing either LOOP or NO LOOP to indicate whether or not all the pieces can be joined into a single loop.

Sample input

4
MF MF
FM FF MF MM
MM FF
MF MF MF MF FF

Sample output

LOOP
LOOP
LOOP
NO LOOP
#include<stdio.h>
#include<string.h>
char a[200];
int main()
{
int n,i;
scanf("%d",&n);
getchar();
while(n--)
{
int m=0,f=0;
gets(a);
for(i=0;i<strlen(a);i++)
{
if(a[i]=='M') m++;
if(a[i]=='F') f++;
}
if(m==f&&m!=1) puts("LOOP");
else puts("NO LOOP");
}
return 0;
}

11586 - Train Tracks的更多相关文章

  1. UVa 11586 - Train Tracks

    题目:给你一些积木碎片,每一个碎片的两端仅仅能是凸或凹(M或F).凸凹可拼起来.是否能拼成一个环. 分析:图论.欧拉回路.推断入度等于出度就可以,即M和F同样且大于1组. 说明:╮(╯▽╰)╭. #i ...

  2. LA 4064 Magnetic Train Tracks

    题意:给定平面上$n(3\leq n \leq 1200)$个无三点共线的点,问这些点组成了多少个锐角三角形. 分析:显然任意三点可构成三角形,而锐角三角形不如直角或钝角三角形容易计数,因为后者有且仅 ...

  3. UVaLive 4064 Magnetic Train Tracks (极角排序)

    题意:给定 n 个不三点共线的点,然后问你能组成多少锐角或者直角三角形. 析:可以反过来求,求有多少个钝角三角形,然后再用总的减去,直接求肯定会超时,但是可以枚举每个点,以该点为钝角的那个顶点,然后再 ...

  4. LA 4064 (计数 极角排序) Magnetic Train Tracks

    这个题和UVa11529很相似. 枚举一个中心点,然后按极角排序,统计以这个点为钝角的三角形的个数,然后用C(n, 3)减去就是答案. 另外遇到直角三角形的情况很是蛋疼,可以用一个eps,不嫌麻烦的话 ...

  5. Zerojudge解题经验交流

    题号:a001: 哈囉 背景知识:输出语句,while not eof 题号:a002: 簡易加法 背景知识:输出语句,while not eof,加法运算 题号:a003: 兩光法師占卜術 背景知识 ...

  6. ACM计算几何题目推荐

    //第一期 计算几何题的特点与做题要领: 1.大部分不会很难,少部分题目思路很巧妙 2.做计算几何题目,模板很重要,模板必须高度可靠. 3.要注意代码的组织,因为计算几何的题目很容易上两百行代码,里面 ...

  7. jQuery中的supersized的插件的功能描述

    Supersized特性: 自动等比例调整图片并填充整浏览器个屏幕. 循环展示图片,支持滑动和淡入淡出等多种图片切换效果. 导航按钮,支持键盘方向键导航. XHTML <div id=" ...

  8. 清华学堂 列车调度(Train)

    列车调度(Train) Description Figure 1 shows the structure of a station for train dispatching. Figure 1 In ...

  9. 2011:Audio Classification (Train/Test) Tasks - MIREX Wiki

    Contents [hide] 1 Audio Classification (Test/Train) tasks 1.1 Description 1.1.1 Task specific mailin ...

随机推荐

  1. Eclipse开启与关闭代码自动提示功能

        Eclipse代码里面的代码提示功能默认是关闭的,只有输入“.”的时候才会提示功能,用vs的用户可能不太习惯 这种,vs是输入任何字母都会提示,下面说一下如何修改eclipse配置,开启代码自 ...

  2. visual c++ 2010安装未成功

    可能是已经安装了其他版本的Microsoft visual studio 参考: http://answers.microsoft.com/zh-hans/windows/forum/windows_ ...

  3. W5100使用中的常见问题

    来自:成都浩然 越来越多的嵌入式网络系统project师喜欢上了W5100,它集TCP/IP协议栈.以太网的MAC和PHY一体,不仅使系统性能得到非常大的提升,也给产品开发工作带来极大的方便.随着W5 ...

  4. Android的BUG(四) - Android app的卡死问题

    做android,免不了要去运行一些跑分程序,常用的跑分程序有quadrant(象限),nbench,安兔兔等.作为系统工程师,对这些跑分 程序都非常的不屑,这个只能是一个不客观的参考,但客户都喜欢拿 ...

  5. pop,墨刀,快现、justinmind 、Axure

    原型设计软件 墨刀:https://modao.cc Justinmind: http://www.zhihu.com/question/26662368/answer/33586218 http:/ ...

  6. VMware三种链接方式

    VMware三种链接方式 第一种:桥接Bridged 如其的说明:connected directly to the physical networkà直接连接到物理网络.如果是通过路由器连接出来的D ...

  7. [置顶] JNI之java传递数据给c语言

    1.首先创建 DataProvider类: package com.pl.ndkpassdata; public class DataProvider { static{ System.loadLib ...

  8. 常见Linux服务器操作系统版本中自带的OpenSSL版本

    下表是常见服务器操作系统版本中自带的OpenSSL版本: 从上表可以看出,目前常用的服务器版本中,默认OpenSSL为1.0.2的只有Ubuntu 16.04 LTS.其他版本如果要升级OpenSSL ...

  9. <脱机手写汉字识别若干关键技术研究>

    脱机手写汉字识别若干关键技术研究 对于大字符集识别问题,一般采用模板匹配的算法,主要是因为该算法比较简单,识别速度快.但直接的模板匹配算法往往无法满足实际应用中对识别精度的需求.为此任俊玲编著的< ...

  10. [C++Boost]程序参数项解析库Program_options使用指南

    介绍 程序参数项(program options)是一系列name=value对,program_options 允许程序开发者获得通过命令行(command line)和配置文件(config fi ...