11586 - Train Tracks
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的更多相关文章
- UVa 11586 - Train Tracks
题目:给你一些积木碎片,每一个碎片的两端仅仅能是凸或凹(M或F).凸凹可拼起来.是否能拼成一个环. 分析:图论.欧拉回路.推断入度等于出度就可以,即M和F同样且大于1组. 说明:╮(╯▽╰)╭. #i ...
- LA 4064 Magnetic Train Tracks
题意:给定平面上$n(3\leq n \leq 1200)$个无三点共线的点,问这些点组成了多少个锐角三角形. 分析:显然任意三点可构成三角形,而锐角三角形不如直角或钝角三角形容易计数,因为后者有且仅 ...
- UVaLive 4064 Magnetic Train Tracks (极角排序)
题意:给定 n 个不三点共线的点,然后问你能组成多少锐角或者直角三角形. 析:可以反过来求,求有多少个钝角三角形,然后再用总的减去,直接求肯定会超时,但是可以枚举每个点,以该点为钝角的那个顶点,然后再 ...
- LA 4064 (计数 极角排序) Magnetic Train Tracks
这个题和UVa11529很相似. 枚举一个中心点,然后按极角排序,统计以这个点为钝角的三角形的个数,然后用C(n, 3)减去就是答案. 另外遇到直角三角形的情况很是蛋疼,可以用一个eps,不嫌麻烦的话 ...
- Zerojudge解题经验交流
题号:a001: 哈囉 背景知识:输出语句,while not eof 题号:a002: 簡易加法 背景知识:输出语句,while not eof,加法运算 题号:a003: 兩光法師占卜術 背景知识 ...
- ACM计算几何题目推荐
//第一期 计算几何题的特点与做题要领: 1.大部分不会很难,少部分题目思路很巧妙 2.做计算几何题目,模板很重要,模板必须高度可靠. 3.要注意代码的组织,因为计算几何的题目很容易上两百行代码,里面 ...
- jQuery中的supersized的插件的功能描述
Supersized特性: 自动等比例调整图片并填充整浏览器个屏幕. 循环展示图片,支持滑动和淡入淡出等多种图片切换效果. 导航按钮,支持键盘方向键导航. XHTML <div id=" ...
- 清华学堂 列车调度(Train)
列车调度(Train) Description Figure 1 shows the structure of a station for train dispatching. Figure 1 In ...
- 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 ...
随机推荐
- OpenSSL命令---rand
用途: 用来产生伪随机字节.随机数字产生器需要一个seed,先已经说过了,在没有/dev/srandom系统下的解决方法是自己做一个~/.rnd文件.如果该程序能让随机数字产生器很满意的被seeded ...
- php 学习笔记 数组2
10.切割数组 array_slice(array, offset, length);返回一个由原始数组中的连续元素组成的新数组,参数1为原始数组,参数2为要复制的起始位置, 参数3要复制的个数:新数 ...
- AddSelf
今天看 C语言深度深度解剖 第58页 看到了这么一段代码,就敲进了dev 谁知居然出现了个死循环.但是我不知道为什么. 贴出来,等有空了再请教别人好好分析,或者是网络上的高人指点一下 //d ...
- struts2--配置文件中使用通配符
struts2的配置文件是 struts.xml.. 在这个配置文件里面可以使用通配符..其中的好处就是,大大减少了配置文件的内容..当然,相应付出的代价是可读性.. 使用通配符的原则是 约定高于配置 ...
- Rsync、Unison及DRBD的比较
一.Rsync Rsync(remote synchronize),顾名思义,可以知道这是一个远程数据同步工具,可通过LAN/WAN快速同步多台主机间的文件.Rsync使用所谓的 “Rsync算法”来 ...
- 评侯捷的<深入浅出MFC>和李久进的<MFC深入浅出>
侯捷的<深入浅出mfc>相信大家都已经很熟悉了,论坛上也有很多介绍,这里我就不多说了. 而李久进的<mfc深入浅出>,听说的人可能就少得多.原因听说是这本书当时没有怎么宣传,而 ...
- Dreamer2.1 发布 新增将Bean解析成xml和json
一个上午,增加两个功能 1.直接将对象解析成XML 2.将对象解析成JSON 对象可以是数组,可以是集合,也可以是单个对象 源码和jar下载地址:http://pan.baidu.com/share/ ...
- C++中的智能指针(auto_ptr)
实际上auto_ptr 仅仅是C++标准库提供的一个类模板,它与传统的new/delete控制内存相比有一定优势.使用它不必每次都手动调用delete去释放内存.当然有利也有弊,也不是全然完美的. 本 ...
- SecureCRT使用Vim出现中文乱码问题的解决
1. 首先保证securecrt本身显示中文是ok的.如果不是,就先解决这一个问题. 2. vi ~/.vimrc 添加set encoding=utf-8 fileencodings=ucs-bom ...
- Linux下安装yum工具
Linux下安装yum工具 http://blog.csdn.net/caoshichaocaoshichao/article/details/13171919