02 2013 档案
摘要:给出一个长度为n的序列A1,A2,A3,...An,求最大连续和。换句话说,要求找到1=<i=<j=<n,使得Ai+...+Aj尽量大。题目似乎很简单,但是在n非常大的时候(如n>10000)时,采用最习惯使用的暴力过的话似乎就有一些难度,下面逐步给出了几种方法,解决问题在可以解出来时,应该找求最优解方法一:枚举直接在i到j之间一一枚举。复杂度O(n^3) 1 #include<stdio.h> 2 int main() 3 { 4 int a[1000],n; 5 while(scanf("%d",&n)!=EOF) 6 { 7
阅读全文
摘要:Description考虑将如此安排在一个 3 x3 行列中的九个时钟:目标要找一个最小的移动顺序次将所有的指针指向12点。 下面原表格列出了9种不同的旋转指针的方法,每一种方法都叫一次移动。 选择1到9号移动方法,将会使在表格中对应的时钟的指针顺时针旋转90度。 移动方法 受影响的时钟 1 ABDE 2 ABC 3 BCEF 4 ADG 5 BDEFH 6 CFI 7 DEGH 8 GHI 9 EFHI Example[但这可能不是正确的方法,请看下面]Input第1-3行: 三个空格分开的数字,每个数字表示一个时钟的初始时间,3,6,9,12。 数字的含意和上面第一个例子一样。Output
阅读全文
摘要:题目链接http://acm.hdu.edu.cn/showproblem.php?pid=4255题目的数据是10000以内的,但是要建400*400的矩阵用一次bfs就可以完成 1 #include<stdio.h> 2 #include<string.h> 3 #include<math.h> 4 int ma[410][410]={0},vis[410][410],dist[410][410],mb[410][410];//mb储存数字,ma储存素数 5 int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1}; 6 int q[4
阅读全文
摘要:题目链接http://acm.hdu.edu.cn/showproblem.php?pid=1312 1 #include 2 #include 3 #define mem(a) memset(a,0,sizeof(a)); 4 using namespace std; 5 const int MA...
阅读全文
摘要:题目链接http://codeforces.com/problemset/problem/6/CAlice and Bob like games. And now they are ready to start a new game. They have placed n chocolate bars in a line. Alice starts to eat chocolate bars one by one from left to right, and Bob — from right to left. For each chocololate bar the time, needed
阅读全文
摘要:输入n,输出满足条件的n*n皇后的排列以及总解数输入:64输出:2 4 6 1 3 53 6 2 5 1 44 1 5 2 6 35 3 1 6 4 242 4 1 33 1 4 22 1 #include<iostream> 2 using namespace std; 3 int n,tot; 4 int C[15]; 5 void print() 6 { 7 int i,ok=0; 8 for(i=0;i<n;i++){ 9 if(ok==0){cout<<C[i]+1;ok=1;}10 else cout<<" "<&
阅读全文
摘要:设大,中,小3个杯子的容量分别为a,b,c。最初只有大杯子装满水,其他两个为空。最少要多少步让某一个杯子中有x升。0<c<b<a<1000输入:6 3 1410 7 35输出: 6 0 0 3 3 0 3 2 1 4 2 0minimum steps:3 10 0 0 3 7 0 3 4 3 6 4 0 6 1 3 9 1 0 9 0 1 2 7 1 2 5 3minimum steps:8 1 #include<iostream> 2 #include<cstring> 3 #include<iomanip> 4 #define m
阅读全文
摘要:输入正整数n,把整数1,2,3...n组成一个环,使得相邻两个整数之和均为素数,输出从整数1开始逆时针的排列。同时一个环恰好只输出一次,n<=16。输入:6输出:1 4 3 2 5 61 6 5 2 4 3 1 #include<iostream> 2 using namespace std; 3 int A[16],vis[17]={0},n; 4 bool isp(int n) 5 { 6 if(n==1)return false; 7 int i; 8 for(i=2;i<n/2;i++)if(n%i==0)return false; 9 return t...
阅读全文

浙公网安备 33010602011771号