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 ...
随机推荐
- vijos 1115 火星人
说了那么多.事实上就是遍历全排列 #include<iostream> #include<cstdio> #include<algorithm> #include& ...
- 随机生成A~Z的字母CharDemo
- Codeforces 57C Array dp暴力找到规律
主题链接:点击打开链接 的非增量程序首先,计算, 如果不增加的节目数量x, 非减少一些方案是x 答案就是 2*x - n 仅仅需求得x就可以. 能够先写个n3的dp,然后发现规律是 C(n-1, 2* ...
- VS2012 创建项目失败,,提示为找到约束。。。。
首先查看 控制面板里已安装的更新 在Microsoft .NET Freamewofk 4.5 小 查看 是否有KB2833957和KB2840642这两个补丁(如下图) 如果有 卸载它 然后 下载 ...
- 面向对象程序设计-C++ Class & Object & Friend Function & Constructor & Destructor【第五次上课笔记】
大家可以下载后用Vim 或者 Sublime Text等文本编辑器查看 以下代码均已折叠,点击“+“即可打开 一开始老师用C语言大作业的例子,写了个 Student 的结构以及相关操作 #includ ...
- Chapter 17 Replication 复制
Chapter 17 Replication 复制 Table of Contents 17.1 Replication Configuration 17.2 Replication Implemen ...
- 基于visual Studio2013解决算法导论之021单向循环链表
题目 单向循环链表的操作 解决代码及点评 #include <stdio.h> #include <stdlib.h> #include <time.h> ...
- 基于visual Studio2013解决C语言竞赛题之0519最大值
题目
- Android 系统稳定性 - ANR(一)
文章都为原创,转载请注明出处,未经允许而盗用者追究法律责任.很久之前写的了,留着有点浪费,共享之.编写者:李文栋 如果你是一个Android应用程序开发人员,你的人生中不可避免的三件事情是:死亡.缴 ...
- 【BZOJ1132】【POI2008】Tro 计算几何 叉积求面积
链接: #include <stdio.h> int main() { puts("转载请注明出处[辗转山河弋流歌 by 空灰冰魂]谢谢"); puts("网 ...