Problem UVA10054-The Necklace Time Limit: 3000 mSec Problem Description Input The input contains T test cases. The first line of the input contains the integer T. The first line of each test case contains an integer N (5 ≤ N ≤ 1000) giving the number o…
My little sister had a beautiful necklace made of colorful beads. Two successive beads in the necklace shared a common color at their meeting point. The figure below shows a segment of the necklace: But, alas! One day, the necklace was torn and the b…
题目大意:有n个珠子,珠子两边的颜色已知,问能否连成一条项链.(两个珠子可以项链当且仅当一个珠子的一边颜色与另一个珠子的另一边颜色相同). 题目分析:欧拉回路.将颜色视作节点,珠子当做边,问题变成了找一条欧拉回路. 欧拉回路存在的条件:无向图:1.图连通:2.无奇点: 有向图:1.忽略边的方向后,图连通:2.每个点的入度都等于出度: 注意:输出回路的时候要逆序输出... 代码如下: # include<iostream> # include<cstdio> # include<…
题目链接:http://uoj.ac/problem/117 题目大意: 解题思路:先判断度数: 若G为有向图,欧拉回路的点的出度等于入度. 若G为无向图,欧拉回路的点的度数位偶数. 然后判断连通性,并且输出路径需要用套圈法(其实我也不是很懂). 还学了一些骚操作: ①用链式前向星存图,如果是有向图,那idx隔两个存一条边,如果是无向图则idx隔一个存一条边,且idx从2开始.这样写的作用就是在寻无向图路径时可以良好地标记,比如第一条无向边里idx=2.3分别对应一条正反边,2和3除2都对应1,…
UVA10054 The Necklace 链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=18806 [思路] 欧拉回路. 把每一种颜色看作结点,每一个珠子看作边,构图后求欧拉回路即用所有的珠子构成一条项链. 需要注意的是ans的加入是逆序的,G记录的是边出现的次数. [代码] #include<cstdio> #include<queue> #include<vector> #includ…
题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=455 Due to the slow 'mod' and 'div' operations with int64 type, all Delphi solutions for the problem 455 (Sequence analysis) run much slower than the same code written in C++ or Java. We do not gua…
CALCULATOR CONUNDRUM   Alice got a hold of an old calculator that can display n digits. She was bored enough to come up with the following time waster. She enters a number k then repeatedly squares it until the result overflows. When the result overf…
题意:有个老式计算器,每次只能记住一个数字的前n位.现在输入一个整数k,然后反复平方,一直做下去,能得到的最大数是多少.例如,n=1,k=6,那么一次显示:6,3,9,1... 思路:这个题一定会出现循环,所以一个个模拟,遇到相同的就再之前所有数中找最大的输出即可. 怎么判断遇到相同的呢?如果装在数组里一一比较显然很慢,如果用v[k]判断k是否出现过,k范围太大空间不够用. 第一种方法是使用STL里的set来判重. #include<cstdio> #include<set> us…
Write an algorithm to determine if a number is "happy". 写出一个算法确定一个数是不是快乐数. A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of the squares of its digits, and repeat th…
Floyd判圈算法 leetcode 上 编号为202 的happy number 问题,有点意思.happy number 的定义为: A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of the squares of its digits, and repeat the process u…