sgu 101 Domino 解题报告及测试数据】的更多相关文章

101. Domino time limit per test: 0.25 sec. memory limit per test: 4096 KB 题解: 求多米诺骨牌按照一定方式放置能否使相邻的位置数字相同.其实就是求无向图的欧拉通路,dfs即可. 但需要注意以下几点: 1.注意是否是连通图. 2.注意自环. 3.注意有两个奇度顶点时深搜起点. 以下是代码: #include <iostream> #include <cstdio> #include <cstring>…
102. Coprimes time limit per test: 0.25 sec. memory limit per test: 4096 KB 题解: 求一个1-10000之间的数 N 的互质数个数.题目很简单,有两种方法: 1.复杂度是O(n^2),依次判断从1到N-1的数是否与N互质. ​2.复杂度是O(n),换一种想法,先求与N不互质的数的个数,然后用N减去即可.例如9,从2开始循环,3与9不互质,那么3的倍数也与9不互质,所以6也与9不互质.因为N很小,所以可以开一个数组a[10…
101. Domino time limit per test: 0.25 sec. memory limit per test: 4096 KB Dominoes – game played with small, rectangular blocks of wood or other material, each identified by a number of dots, or pips, on its face. The blocks usually are called bones,…
求欧拉路径...直接dfs即可,时间复杂度O(N) --------------------------------------------------------------------------- #include<cstdio> #include<cstring> #include<algorithm> #include<stack>   using namespace std;   #define X(i) Edge[i].first #defin…
104. Little shop of flowers time limit per test: 0.25 sec. memory limit per test: 4096 KB 问题: 你想要将你的花窗安排得最具美感.有F束花,每一束花都不一样,至少有F个按顺序排成一行的花瓶.花瓶从左到右,依次编号1-V.而花放置的位置是可以改变的,花依次编号1到F.花的序号有一个特征,即是序号决定了花束出现在花瓶里的顺序.例如,有两束花编号i和j,满足i<j,那么i所在的花瓶一定要在j所在花瓶的左边,即是i…
103. Traffic Lights Time limit per test: 0.25 second(s) Memory limit: 4096 kilobytes 题解: 1.其实就是求两点间的最短路,不过加了交通灯的限制,使得两点间的所需时间并不只是由路程决定. 2.只有一条路两个端点的交通灯颜色相同时,该路才可以通过.但是这有一种情况,当两个交通灯处于不同颜色时,经过t时间,交通灯又恰好处于不同颜色,由于最初有一个颜色预变时间riC以及蓝色tiB.紫色周期tiP ,那么就需要计算交通灯…
100.A+B time limit per test: 0.25 sec. memory limit per test: 65536 KB 题解:上手题,不解释. 直接上代码: #include <iostream> using namespace std; int main(){ int a, b; cin >> a >> b; cout << a + b << endl; return 0; }…
题目链接: http://acm.sgu.ru/problem.php?contest=0&problem=101 题意: N个多米诺骨牌,每个骨牌左右两侧分别有一个0~6的整数(骨牌可以旋转以调换其左右两数),求一种把这些骨牌从左到右排列的方案,使得所有相邻的两数字相等(即左边骨牌右侧的数字等于右边骨牌左侧的数字). 分析: 把数字当成点,骨牌当做边.构成无向图,求一发欧拉道路即可. 无向图求欧拉路径还是很好写的. 欧拉路径深入讲解:http://blog.chinaunix.net/uid-…
Array Diversity Time Limit:404MS     Memory Limit:0KB     64bit IO Format:%lld & %llu   Description Here we go! Let's define the diversity of a list of numbers to be the difference between the largest and smallest number in the list. For example, the…
时间限制: 0.5 sec 空间限制: 4096 KB 描述 多米诺骨牌,一种用小的方的木块或其他材料,每个都被一些点在面上标记,这些木块通常被称为骨牌.每个骨牌的面都被一条线分成两个   方形,两边各有一定点数.   N个多米诺骨牌,每个骨牌左右两侧分别有一个0~6的整数(骨牌可以旋转以调换其左右两数), 求一种把这些骨牌从左到右排列的方案,使得所有相邻的两数字相等(即左边骨牌右侧的数字等于右边骨牌左侧的数字). 输入 第一行是一个整数N(1 ≤ N ≤ 100),表示骨牌的数量.接下来的N行…