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 ...
随机推荐
- JavaScript+XML+VBA导出报表初步构想
最近在做人事档案管理系统遇到的一个问题就是种类多.数量大的报表打印问题.这个系统的一个特点就是信函打印,各种介绍信.各种证明信.对于这样的重复性的功能,最好的方法就是所有的报表实现格式套用. 经过分析 ...
- SVN基础命令手册
SVN版本号:1.5 及更新版本号 名词说明: WC:Working Copy 你的工作区 Versioned:受控的:受版本号控制的 SVN是什么? SVN是开源的版本号控制系统. 比CVS很多其它 ...
- server配置学习 ---- 关闭防火墙
iptables 一种网络防火墙,在LINUX下使用,RedHat9.0版本号以上自带. 它能够实现NAT转换.能够做上网代理. 首先对于server的配置第一步来说就是关闭防火墙.在没有图形化中的l ...
- poj1742 多重背包的可行性问题
http://poj.org/problem? id=1742 Description People in Silverland use coins.They have coins of value ...
- PHP - 直接输出对象的版本问题
- Android空指针异常的常见情况
把我经常遇到的nullpoitException写在这里,以便以后自己查找原因. 1.用findViewById(param )的方法获取一个view对象的时候,有的时候其实应该是获取一个layout ...
- PHP面向对象基础实例
<?phpclass marine{ public $blood = 50; //剩余的血 public $kills = 0; //杀敌数量 static $all_num = 0;//兵的数 ...
- 使用DiskGenius对虚拟机磁盘进行压缩
使用虚拟机的用户是否感觉到您的虚拟磁盘文件越来越大,都快把宝贵的磁盘空间(宿主机物理硬盘)占满了呢? 有人会想到,我直接启动虚拟机,然后把里面没用的数据删除了,不就行了吗?实际测试发现,这样删除后,存 ...
- iOS开发- 获取精确剩余电量
[UIDevice currentDevice].batteryMonitoringEnabled = YES; double deviceLevel = [UIDevice currentDevic ...
- YouTube为什么打不开?以及简便的訪问的方法/解决方式!
在站点统计中看到好多人通过百度或者谷歌(Google)搜索引擎搜:YouTube怎么上不去,怎样不用代理server訪问YouTube,YouTube上不去的解决的方法,YouTube怎样訪问等等.事 ...