【习题 5-2 UVA-1594】Ducci Sequence】的更多相关文章

A Ducci sequence is a sequence of n-tuples of integers. Given an n-tuple of integers (a1, a2, · · · , an), the next n-tuple in the sequence is formed by taking the absolute differences of neighboring integers: (a1, a2, · · · , an) → (|a1 − a2|, |a2 −…
       Ducci Sequence Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu   Description A Ducci sequence is a sequence of n-tuples of integers. Given an n-tuple of integers (a1, a2, ... , an), the next n-tuple in the sequence is fo…
Ducci Sequence Description   A Ducci sequence is a sequence of n-tuples of integers. Given an n-tuple of integers (a1, a2, ... , an), the next n-tuple in the sequence is formed by taking the absolute differences of neighboring integers: ( a1, a2, ...…
水题,算出每次的结果,比较是否全0,循环1000次还不是全0则LOOP AC代码: #include <iostream> #include <cstdio> #include <cstdlib> #include <cctype> #include <cstring> #include <string> #include <sstream> #include <vector> #include <set…
想麻烦了.这题真的那么水啊..直接暴力模拟,1000次(看了网上的200次就能A)后判断是否全为0,否则就是LOOP: #include <iostream> #include <sstream> #include <cstdio> #include <cstring> #include <cmath> #include <string> #include <vector> #include <set> #in…
题目 题目     分析 真的快疯了,中午交了一题WA了好久,最后发现最后一个数据不能加\n,于是这次学乖了,最后一组不输出\n,于是WA了好几发,最后从Udebug发现最后一组是要输出的!!!     代码 #include <cstdio> #include <cmath> #include <algorithm> using namespace std; int n,a[25]; bool s() { for(int i=0;i<n;i++) if(a[i]…
题目: 1594 - Ducci Sequence Asia - Seoul - 2009/2010A Ducci sequence is a sequence of n-tuples of integers. Given an n-tuple of integers (a1, a2, ... , an), the next n-tuple in the sequence is formed by taking the absolute differences of neighboring in…
  A Ducci sequence is a sequence of n-tuples of integers. Given an n-tuple of integers (a1,a2,···,an), the next n-tuple in the sequence is formed by taking the absolute differences of neighboring integers: (a1,a2,···,an) → (|a1 − a2|,|a2 − a3|,···,|a…
UVa 1584 题目大意:给定一个含有n个字母的环状字符串,可从任意位置开始按顺时针读取n个字母,输出其中字典序最小的结果 解题思路:先利用模运算实现一个判定给定一个环状的串以及两个首字母位置,比较二者字典序大小的函数, 然后再用一层循环,进行n次比较,保存最小的字典序的串的首字母位置,再利用模运算输出即可 /* UVa 1584 Circular Sequence --- 水题 */ #include <cstdio> #include <cstring> //字符串s为环状,…
Description   A Ducci sequence is a sequence of n-tuples of integers. Given an n-tuple of integers (a1, a2, ... , an), the next n-tuple in the sequence is formed by taking the absolute differences of neighboring integers: ( a1, a2, ... , an)  (| a1 -…
书上具体所有题目:http://pan.baidu.com/s/1hssH0KO 代码:(Accepted,20 ms) //UVa1594 - Ducci Sequence #include<iostream> #include<algorithm> #include<cmath> #include<vector> using namespace std; int T,N; bool is_zero(vector<int> &d) {…
A Ducci sequence is a sequence of n-tuples of integers. Given an n-tuple of integers (a1, a2, ... , an), the next n-tuple in the sequence is formed by taking the absolute differences of neighboring integers: ( a1, a2, ... , an)  (| a1 - a2|,| a2 - a3…
题目传送门 题意:找对称的,形如:123454321 子序列的最长长度 分析:LIS的nlogn的做法,首先从前扫到尾,记录每个位置的最长上升子序列,从后扫到头同理.因为是对称的,所以取较小值*2-1再取最大值 代码: /************************************************ * Author :Running_Time * Created Time :2015-8-5 21:38:32 * File Name :UVA_10534.cpp ******…
// uva 10534 Wavio Sequence // // 能够将题目转化为经典的LIS. // 从左往右LIS记作d[i],从右往左LIS记作p[i]; // 则最后当中的min(d[i],p[i])就是这个波动序列的一半 // 在这最后的min(d[i],p[i]) * 2 + 1 的最大值就是我们所要求的答案 // // 这题開始想的最后的答案是d[i]==p[i]的时候求最大. // 可是这样是不正确的,比如n=4, // 1,3,1,0 // 最长的应该是3,可是我的答案是1,…
题意: 对于一个n元组(a0,a1,...),一次变换后变成(|a0-a1|,|a1-a2|,...) 问1000次变换以内是否存在循环. 思路: 模拟,map判重 代码: #include <cstdio> #include <cstring> #include <map> #include <cmath> #include <algorithm> using namespace std; struct Node{ ]; int n; void…
大白书上P42那个计算器的题目就用到了这个办法,Floyd判圈法. 当然,用STL里的map也是可以的. #include <cstdio> #include <cmath> ; int n; int a[maxn], b[maxn], c[maxn]; void next(int a[]) { ; i < n - ; i++) a[i] = std::abs(a[i] - a[i + ]); a[n - ] = a[]; } bool equal(int a[], int…
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] map加vector轻松搞定. [代码] #include <bits/stdc++.h> using namespace std; typedef vector <int> Vi; Vi v; map <Vi,int> mmap; int n; int main() { //freopen("F:\\rush.txt", "r", stdin); int T;…
题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4459 题目意思:给出一个字符串,求出该字符串的最小字典序 暴力求解即可,用 ans 保存最小字典序的第一个字符的下标.(好像这方法有点慢,测试的时候,第二个 test 出来的答案好像要等那么一段时间 = =, 3s 应该挺够的) #include <iostream>…
题意:用最少的括号将给定的字符串匹配,输出最优解.可能有空行. 思路:dp. dp[i][j]表示将区间i,j之间的字符串匹配需要的最少括号数,那么 如果区间左边是(或[,表示可以和右边的字符串匹配,枚举中间断点k,如果str[i]==str[k]则dp[i][j]=min(dp[i][j],dp[i+1][k-1]+dp[k+1][j])表示不需要加入新的括号,也可以插入新的括号则dp[i][j]=min(dp[i][j],dp[i+1][k]+dp[k+1][j]+1). 如果区间最左边字符…
Problem B Number Sequence Input: standard input Output: standard output Time Limit: 1 second A single positive integer i is given. Write a program to find the digit located in the position i in the sequence of number groups S1S2…Sk. Each group Sk con…
题目连接:10706 - Number Sequence 题目大意:有一个有0 ~ 9组成的序列,1   1 2    1 2 3   1 2 3 4   1 2 3 4 5 ....就是第一位为1. 第二为为1 ,第三为为2, 然后10 的部分注意下, 为1  和0 两个, 100 就是1 , 0和0 三位,以此类推, 要求给出tmp, 输出序列中的tmp位为什么数字. 解题思路:数据很大,肯定不能模拟,找规律. 这两个是为推出来的用来打表的公式: 1.sum[i] = sum[i - 1]…
题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=17&page=show_problem&problem=1475 Dynamic Programming. 最长增长子序列.推荐一个链接:http://www.cnblogs.com/liyukuneed/archive/2013/05/26/3090402.html.按照链接里的方法三(其他的会有TLE…
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1475 正反一次lis然后去min{左,右}*2-1即可 #include <cstdio> #include <cstring> #include <cmath> #include <string> #include <iostream&…
链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4501 题意: 定义如下正规括号序列(字符串):1.空序列是正规括号序列.2.如果S是正规括号序列,那么(S)和[S]也是正规括号序列.3.如果A和B都是正规括号序列,那么AB也是正规括号序列.输入一个长度不超过100的,由“(”.“)”.“[”.“]”构成的序列,添加尽量少的括号,…
Wavio Sequence  Wavio is a sequence of integers. It has some interesting properties. ·  Wavio is of odd length i.e. L = 2*n + 1. ·  The first (n+1) integers of Wavio sequence makes a strictly increasing sequence. ·  The last (n+1) integers of Wavio s…
题意  给你一个环形串   输出它以某一位为起点顺时针得到串的最小字典序 直接模拟   每次后移一位比較字典序就可以  注意不能用strcpy(s+1,s)这样后移  strcpy复制地址不能有重叠部分 #include<cstdio> #include<cstring> using namespace std; const int N = 150; char s[N], ans[N], c; int t, l; int main() { scanf ("%d"…
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=105116#problem/E 题意:添加最少的括号,让每个括号都能匹配并输出 分析:dp[i][j]表示第i个到第j个需要添加的最少的括号,pos[i][j] = k;表示i到j间第k个需要加括号: 如果str[i]和str[j]匹配,那么dp[i][j] = max(dp[i + 1][j - 1], dp[i][j]); 如果str[i]和str[j]不匹配,那么dp[i][j]…
题目大意:Sk表示从1到k的字符序列,如S4为1234,现如今有如下的序列S1S2...Sk,形如1 12 123 1234这样的序列,给一个数n,让你去这个序列第n个位置上的数字. 可以构建出一个Sk序列的表格,然后用一个数组sum[i]记录该序列到i是有几位,这样就可以计算出n位于那个Sx序列中,求得在该序列中的位置,再查表即可. #include <cstdio> #include <cmath> #include <cctype> #include <cl…
题意:给定一个括号序列,将它变成匹配的括号序列,可能多种答案任意输出一组即可.注意:输入可能是空串. 思路:D[i][j]表示区间[i, j]至少需要匹配的括号数,转移方程D[i][j] = min(D[i][k] + D[k+1][j], D[i][j]).     输入时,可能是空串应该用gets.fgets.getline,应注意换行符的吸收.每组数据前有一个换行符,输出的两组数据之间有换行. AC代码: #include<cstdio> #include<vector> #…
#include <iostream> #include <algorithm> #include <cmath> #include <cstdio> #include<cstdlib> #include<cstring> #include <vector> #include <queue> #include <map> using namespace std; #define maxn 10010…