最近都在看c++,因为也算是从新开始在学习,以前 都没有认真地看,现在晚上都抽空在看,最近忙得事情太多了,导致做题时间都没有了,我要补补补~~~~,并且抓紧时间学完c++。 加油!!!! 晚安~~~
其实我以前看过,但是没有认真地学过,只是知道得很范,但是现在下定决心学重新学习!
哈哈 曾现在还有时间, 每天看一点完成课后的习题,积累! 我要想 蜗牛 一样,一步一步往上爬!!
我会努力的!
这道题思路简单!
1 #include <cstdio>
2 #include <algorithm>
3 using namespace std;
4
5 int main()
6 {
7 int s1[1000];
8 int s2[1000];
9 int m;
10 scanf ( "%d",&m );
11 for ( int i = 0; i != m; ++i )
12 {
13 scanf ( "%d",&s1[i] );
14 s2[i] = 1;
15 }
16 int max1 = 0;
17 int max2;
18 for ( int i = 0; i != m; ++i )
19 {
20 max2 = 0;
21 for ( int j = 0; j != i; ++j )
22 {
23 if ( s1[i] > s1[j] )
24 max2 = max( max2,s2[j] );
25 }
26 s2[i] += max2;
27 if ( s2[i] > max1 )
28 max1 = s2[i];
29 }
30 printf ( "%d\n",max1 );
31 }
1 #include <cstdio>
2
3 int main()
4 {
5 int s,d;
6 while ( scanf ( "%d",&s ) != EOF )
7 {
8 scanf ( "%d",&d );
9 int k = 1;
10 int s1,d1;
11 s1 = 4 * s;
12 d1 = d;
13 for ( ; k <= 5; ++k ) // 5 种情况 ssssdssssdss,sssddsssddss,ssdddssdddss,sddddsddddsd,dddddddddddd.
14 {
15 s1 = s1 - k * d1;
16 if ( s1 <= 0 )
17 break;
18 s1 = (4 - k) * s;
19 }
20 //printf ( "%d\n",s1 );
21 if ( k <= 3 )
22 s1 = ( 12 - 2 * k ) * s - 2 * k * d;
23 else if ( k == 4 )
24 s1 = ( 12 - ( 2 * k + 1 ) ) * s - ( 2 * k + 1 ) * d;
25 if ( k == 5 || s1 <= 0 )
26 printf ( "Deficit\n" );
27 else printf ( "%d\n",s1 );
28 }
29 return 0;
30 }
31
32
题意:
每个月会给出一个财务报告:赢利或者亏空 如果赢利则赢利s,如果亏空则亏空d
(12个月都一样,只有赢利s或者亏空d两种情况)
每五个月也会给出一个报告(1~5 ,2~6 。。。)一年一共有8次这样的报告,已知这8次都报告亏空
问整年情况:如果亏空则输出Deficit,如果赢利,输出整年可能赢利的最大值;
动动笔!!!
1 #include <cstdio>
2 #include <cstring>
3 #include <algorithm>
4 using namespace std;
5
6 int main()
7 {
8 char s1[501];
9 char s2[501];
10 while ( scanf ( "%s",s1 ) != EOF ){
11 scanf ( "%s",s2 );
12 int s3[500][500];
13 int l1,l2;
14 l1 = strlen( s1 );
15 l2 = strlen( s2 );
16 for ( int i = 0; i != l1+1; ++i )
17 for ( int j = 0; j != l2 + 1; ++j )
18 s3[i][j] = 0;
19 int max1 = 0;
20 for ( int i = 0; i != l1; ++i )
21 for ( int j = 0; j != l2; ++j )
22 {
23 if ( s1[i] == s2[j] )
24 {
25 s3[i+1][j+1] = s3[i][j] + 1;
26 if ( s3[i+1][j+1] > max1 )
27 max1 = s3[i+1][j+1];
28 }
29 else
30 s3[i+1][j+1] = max (s3[i+1][j], s3[i][j+1]);
31 }
32 printf ( "%d\n",max1 );
33 }
34 return 0;
35 }
36
这题其实不难,思想很简单,就是记录下前一个字母的最长子序列!
哈哈~~虽然参考书后还是相比较久,但总算会了!
这题简单到不行,这题教育我,不要被方法圈住,有时候多动动笔,往后面写,规律就出来了!
1 #include <cstdio>
2
3 int main()
4 {
5 int n;
6 int c = 0;
7 scanf ( "%d",&n );
8 long s1[47];
9 while ( n != 0 )
10 {
11 int m;
12 scanf ( "%d",&m );
13 s1[0] = 1;
14 s1[1] = 2;
15 for ( int i = 2; i < m+1; ++i )
16 s1[i] = s1[i-1] + s1[i-2];
17 printf ( "Scenario #%d:\n",++c );
18 printf ( "%d\n",s1[m] );
19 printf ( "\n" );
20 --n;
21 }
22 return 0;
23 }
24
25
26
想了一下午的题目,天啊 居然还是没有理解,多重背包问题,但是值得安慰的是哈哈,我居然搞懂了一个菜鸟的问题,那就是01背包问题~dp! 有时候真有点垂头丧气的,我是算法的初学者,好烦!看题目,有时候都看得模模糊糊的~这是更让人郁闷的!一直要摸索,总是一个人一个人在这条漆黑的道路上往前走,只有撞墙才知道我自己走错了!无奈,只好在想想其他方法!
思考~经过我多次撞墙,现在我必须学会努力,我明白了,我一定得要想清楚整个框架在动手开始写!不能每次都如此的草率下手,想到什么就写,以前真的让我吃大亏了! 还有,我不聪明,所以每次想题目总是告诫自己一定要开发思维,想想这种问题可能是以前的变形等等! 我总是安慰自己啊哈哈,我要是一下看出题目的解法,那我岂不是大牛了,既然我不是大牛,因此我就一定得自己冷静下来花更多的时间思考,顺便开发我的思维哈哈,让自己变得聪明嘛!
我的计划还在进行,我也会努力走下去,万事开头难,每天提醒自己不要放弃,一点挫折怕什么!引用我老大的一句话:想破脑子你总会想明白的!
我得冷静,冷静,冷静,然后继续想!
1 #include <cstdio>
2 #include <algorithm>
3 using namespace std;
4
5 int main()
6 {
7 //freopen( "in.txt","r",stdin );
8 int s1[100][100];
9 int n;
10 scanf ( "%d",&n );
11 for ( int i = 0; i != n; ++i )
12 for ( int j = 0; j <= i; ++j )
13 scanf ( "%d",&s1[i][j] );
14 int max1[100];
15 for ( int i = 0; i != n; ++i )
16 max1[i] = s1[n-1][i];
17 //for ( int i = 0; i != n; ++i )
18 // printf ( "%d ",max[i] );
19 for ( int i = n - 2;i >= 0; --i )
20 {
21 int sum1 = 0;
22 int sum2 = 0;
23 int k = 0;
24 for ( int j = 0; j != i+1; ++j )
25 {
26 sum1 = s1[i][j] + max1[k];
27 sum2 = s1[i][j] + max1[k+1];
28 max1[k] = max( sum1,sum2 );
29 ++k;
30 }
31 }
32 printf ( "%d\n",max1[0] );
33 }
1 #include <cstdio>
2 #include <cstring>
3 #include <algorithm>
4 using namespace std;
5
6 int main()
7 {
8 //freopen( "in.txt","r",stdin );
9 int s1[100][100];
10 int f,v;
11 scanf ( "%d%d",&f,&v );
12 for ( int i = 0; i != f; ++i )
13 for ( int j = 0; j != v; ++j )
14 scanf ( "%d",&s1[i][j] );
15 int s2[100][100];
16 int j2 = 0;
17 for ( int i = 0; i != f; ++i ) // 把需要判断的数挑选出来
18 {
19 int k1 = 0;
20 j2 = 0;
21 for ( int j = i; j <= v-f+i ; ++j ) //主要是 v-f+1 控制条件
22 s2[i][j2++] = s1[i][j];
23 }
24 int max[1000];
25 for ( int i = f - 1,j = 0; j != j2;++j )
26 max[j] = s2[i][j];
27 //for ( int j = 0; j != j2; ++j )
28 // printf ( "%d \n",max[j] );
29 for ( int i = f - 2; i >= 0; --i ) // DP 主要 从最后一行往上判断 每个数sum的max;
30 {
31 int max1;
32 for ( int j = 0; j != j2; ++j )
33 {
34 max1 = -500;
35 int sum;
36 for ( int j1 = j; j1 != j2; ++j1 )
37 {
38 sum = s2[i][j] + max[j1];
39 if ( sum > max1 )
40 max1 = sum;
41 }
42 max[j] = max1;
43 }
44 }
45 sort( max,max+j2 );
46 printf ( "%d\n",max[j2-1] );
47 return 0;
48 }
49
1 #include <cstdio>
2 #include <malloc.h>
3 #include <algorithm>
4 using namespace std;
5
6 struct nod
7 {
8 int l;
9 int w;
10 bool n;
11 };
12
13 int q_sort( nod *s3[5001],int q_head,int q_rear ) // 快排
14 {
15 int i = q_head-1;
16 int j = q_head;
17 for ( ; j < q_rear; ++j )
18 {
19 if ( s3[j]->l < s3[q_rear]->l )
20 {
21 ++i;
22 swap( s3[i]->l,s3[j]->l );
23 swap( s3[i]->w,s3[j]->w );
24 }
25 else if ( s3[j]->l == s3[q_rear]->l )
26 {
27 if ( s3[j]->w < s3[q_rear]->w )
28 swap( s3[j]->w,s3[q_rear]->w ); // 重点: 当两个长度相等时,要把重量按升序排列,因为这样才不会导致后来会少算!!!
29
30 }
31
32 }
33 swap( s3[i+1]->l,s3[q_rear]->l );
34 swap( s3[i+1]->w,s3[q_rear]->w );
35 return i+1;
36 }
37
38
39
40
41 void sort( nod *s2[5001],int head,int rear )
42 {
43 int i;
44 if ( head < rear )
45 {
46 i = q_sort( s2,head,rear );
47 sort( s2,head,i-1 );
48 sort( s2,i+1,rear );
49 }
50 }
51
52
53 int main()
54 {
55 //freopen( "in.txt","r",stdin );
56 int y;
57 scanf( "%d",&y );
58 while ( y != 0 )
59 {
60 int m;
61 scanf ( "%d",&m );
62 nod *s1[5001];
63 int l,w;
64 for ( int i = 0; i != m; ++i )
65 {
66 s1[i] = ( nod * )malloc( sizeof( nod ) );
67 scanf ( "%d%d",&l,&w );
68 s1[i]->l = l;
69 s1[i]->w = w;
70 s1[i]->n = false;
71 }
72 sort( s1,0,m-1 );
73 int time = 0;
74 for ( int i = 0; i != m; ++i ) // 贪心
75 {
76 if ( s1[i]->n == false )
77 {
78 int j = i;
79 int k = s1[i]->w;
80 while ( j != m )
81 {
82 if ( s1[j]->n == false && s1[j]->w >= k )
83 {
84 s1[j]->n = true;
85 k = s1[j]->w;
86 }
87 ++j;
88 }
89 ++time;
90 }
91 }
92 printf ( "%d\n",time );
93 --y;
94 }
95 return 0;
96 }
97