0%

昨天上完课六点开的题,做了一天UVa之后困得要死,做培训提出了各种喜闻乐见的错误。。

除了运行错误和内存超限,其他的错误犯了个遍。。

第一题水题一个。。

Ac代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <iostream>
#include <cstring>
#define maxn 110
using namespace std;
void print(int i)
{
switch(i)
{
case 1:cout<<"yi";break;
case 2:cout<<"er";break;
case 3:cout<<"san";break;
case 4:cout<<"si";break;
case 5:cout<<"wu";break;
case 6:cout<<"liu";break;
case 7:cout<<"qi";break;
case 8:cout<<"ba";break;
case 9:cout<<"jiu";break;
case 0:cout<<"ling";break;
}
}
int main()
{
char a[maxn]={0};
while(cin>>a)
{
int sum=0,b,c,d;
for(int i=0;i<strlen(a);i++)
sum+=a[i]-'0';
d=sum/100;
b=sum%100/10;
c=sum%10;
if(d)
{
print(d);
cout<<" ";
}
if(d!=0||b!=0)
{
print(b);
cout<<" ";
}
print(c);
cout<<endl;
memset(a,0,sizeof(a));
}
return 0;
}

第二题是求最大连续和的,之前上课学长说还有种比二分扫描更快的方法,只需要一次扫描。一开始没理解对结束位置的取值。后来子序列开头和结尾一直没有找好,错了好几次 。。

Ac代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include<iostream>
#include<algorithm>
#define maxn 5050
using namespace std;
int main()
{
int n,a[maxn],t=1;
cin>>n;
while(n--)
{
int j=0,m,st=0,ed=0,sum=0,sum_max=0;
cin>>m;
for(int i=0;i<m;i++)
{
cin>>a[i];
if(a[i]<=0)
j++;
}
if(j==m)
{
int maxm=0;
for(int i=0;i<m;i++)
if(a[maxm]<a[i])
maxm=i;
cout<<"Case "<<t<<":"<<endl;
cout<<a[maxm]<<" "<<maxm+1<<" "<<maxm+1<<endl;;
t++;
if(n)
cout<<endl;
continue;
}
int k=0;
for(int i=0;i<m;i++)
{
if(sum<0)
k=i;
sum=max(0,sum)+a[i];
if(sum>sum_max)
{
st=k;
ed=i;
}
sum_max=max(sum_max,sum);
}
cout<<"Case "<<t<<":"<<endl;
cout<<sum_max<<" "<<st+1<<" "<<ed+1<<endl;;
t++;
if(n)
cout<<endl;
}
return 0;
}

第三题是求字母算式的,也挺水的,但一开始理解错了题目的意思,以为都是两位数加两位数。。

Ac代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include<iostream>
#include<cstring>
#define maxn 10
using namespace std;
char a[maxn][6],b[maxn][6];
int t1,t2,sum;
int exchange(char c[])
{
if(!strcmp(c,"zero"))
return 0;
if(!strcmp(c,"one"))
return 1;
if(!strcmp(c,"two"))
return 2;
if(!strcmp(c,"three"))
return 3;
if(!strcmp(c,"four"))
return 4;
if(!strcmp(c,"five"))
return 5;
if(!strcmp(c,"six"))
return 6;
if(!strcmp(c,"seven"))
return 7;
if(!strcmp(c,"eight"))
return 8;
if(!strcmp(c,"nine"))
return 9;
return 0;
}
int main()
{
while(1)
{
int asum=0,bsum=0;
t1=t2=0;
sum=0;
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
for(int i=0;i<maxn;i++)
{
cin>>a[i];
if(!strcmp(a[i],"+"))
break;
t1++;
}
for(int i=0;i<maxn;i++)
{
cin>>b[i];
if(!strcmp(b[i],"="))
break;
t2++;
}
if(t1==1&&t2==1&&!strcmp(a[0],"zero")&&!strcmp(b[0],"zero"))
return 0;
for(int i=0;i<t1;i++)
{
asum*=10;
asum+=exchange(a[i]);
}
for(int i=0;i<t2;i++)
{
bsum*=10;
bsum+=exchange(b[i]);
}
sum=asum+bsum;
cout<<sum<<endl;
}
return 0;
}

第四题求素数,一开始直接拿学长给的代码用了,换了两种代码,全部TLE。。

后来自己简化求素数流程。只要能不被比自己小的素数整除的数就是素数。。交了一次格式错了。。。

最后改对了。。

Ac代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <cstdio>
#include <cmath>
#include <iostream>
using namespace std;
int p[500050];
int is_p(int n,int j)
{
int i;
int c=sqrt(n);
for(i=0;i<j&&p[i]<=c;i++) if(n%p[i]==0) return 0;
return 1;
}
int main() {
int m,n;
while(cin>>m>>n)
{
p[0]=2;p[1]=3;p[2]=5;p[3]=7;p[4]=11;
int t=5;
for(int i=12;t<=n;i++)
{
if(is_p(i,t))
{
p[t]=i;
t++;
}
}
t=0;
for(int i=m-1;i<n;i++)
{
cout<<p[i];
t++;
if(t%10==0||i==n-1)
cout<<endl;
else
cout<<" ";
}
cout<<endl;
}
return 0;
}

第五题水题,建个数组就好了,比起UVa其他的题差远了。。

Ac代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <iostream>
#include <cstring>
#include <cstdlib>
#define maxn 35
using namespace std;
int a[maxn][maxn];
int m,n;
int is_biggest(int i,int j)
{
if(i-1>=0&&a[i-1][j]>=a[i][j])
return 0;
if(j-1>=0&&a[i][j-1]>=a[i][j])
return 0;
if(j+1<n&&a[i][j+1]>=a[i][j])
return 0;
if(i+1<m&&a[i+1][j]>=a[i][j])
return 0;
return 1;
}
int main()
{
int first=1;
while(cin>>m>>n)
{
if(first)
first=0;
else
cout<<endl;
memset(a,0,sizeof(a));
for(int i=0;i<m;i++)
for(int j=0;j<n;j++)
cin>>a[i][j];
int t=1;
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
{
if(is_biggest(i,j))
{
cout<<a[i][j]<<" "<<i+1<<" "<<j+1<<endl;
t=0;
}
}
}
if(t)
cout<<"None "<<m<<" "<<n<<endl;
}
return 0;
}

最后写几句,审题错太可怕。一开始B、C两道题审题错,死活不过,问清楚题目要求之后一次过的。还有求运行效率问题,以后一定要尽量精简代码。

** 本文迁移自我的CSDN博客,格式可能有所偏差。 **

又刷了十天的题,这十天还粗略地读了读C++的书,感觉提升挺大的。这几天刷题,也暴露了许多问题,各种细节的处理不到位,考虑不够周全。还总出各种粗心错。有些时候 审题也不够仔细,不能正确理解题意,这个要提升只能靠多刷题了。

到现在一共做了30道UVa上的题了。这十天做题量,少了一半,有题目难度的原因,还有就是最近事挺多的,没多少时间刷题,后面的题难度上升了挺多的,做题速度可能会 越来越慢,还是要坚持啊。。

还有就是每天晚上做题都到很晚,影响身体健康,感觉最近头发掉的越来越多了。。。

以后尽量早睡,找其他课余时间刷题。。

** 本文迁移自我的CSDN博客,格式可能有所偏差。 **

输入n个IP地址,求满足该地址的最小网络地址和子网掩码。

我是进制转换之后做的,貌似直接用位运算也可以。转换之后依次对比,主要考察的还是细节的处理,循环时数组一定要清空。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include<iostream>
#include<cstdio>
#include<cstring>
#define maxn 1010
#define maxm 40
using namespace std;
char str[maxn][maxm],ip2[maxn],mask2[maxn];
int bt[maxn][4],ip[4],mask[4];
int main()
{
int n;
while(cin>>n)
{
memset(ip,0,sizeof(ip));
memset(mask,0,sizeof(mask));
memset(str,0,sizeof(str));
memset(ip2,0,sizeof(ip2));
memset(mask2,0,sizeof(mask2));
memset(bt,0,sizeof(bt));
int z=32;
for(int i=0;i<n;i++)
scanf("%d.%d.%d.%d",&bt[i][0],&bt[i][1],&bt[i][2],&bt[i][3]);
for(int i=0;i<n;i++)
{
for(int j=0;j<4;j++)
{
int t=128;
for(int k=0;k<8;k++)
{
if(bt[i][j]-t>=0)
{
str[i][j*8+k]='1';
bt[i][j]-=t;
}
else
str[i][j*8+k]='0';
t/=2;
}
}
}
for(int i=0;i<32;i++)
{
int j=0;
for(j=0;j<n;j++)
{
if(str[0][i]!=str[j][i])
break;
}
if(j==n)
{
ip2[i]=str[0][i];
mask2[i]='1';
}
else
{
z=i;
break;
}
}
for(int i=z;i<32;i++)
{
ip2[i]='0';
mask2[i]='0';
}
for(int i=0;i<4;i++)
{
int x=128;
for(int j=0;j<8;j++)
{
if(ip2[i*8+j]=='1')
ip[i]+=x;
if(mask2[i*8+j]=='1')
mask[i]+=x;
x/=2;
}
}
cout<<ip[0]<<"."<<ip[1]<<"."<<ip[2]<<"."<<ip[3]<<endl;
cout<<mask[0]<<"."<<mask[1]<<"."<<mask[2]<<"."<<mask[3]<<endl;
}
return 0;
}

** 本文迁移自我的CSDN博客,格式可能有所偏差。 **

题目不难,是判断骰子是否等价。昨天晚上开始打的,交了一次WA,今天换了个思路做又WA,感觉没地方错,最后万万没想到是把TRUE打成TURE了。。。改过来之后 直接Ac。。以后这种低级错误要注意。。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include<iostream>
#include<cstring>
#define maxn 15
using namespace std;
char a[maxn],b[maxn],str[maxn];
void revolve_x()
{
char c;
c=b[0];
b[0]=b[1];
b[1]=b[5];
b[5]=b[4];
b[4]=c;
}
void revolve_y()
{
char c;
c=b[1];
b[1]=b[3];
b[3]=b[4];
b[4]=b[2];
b[2]=c;
}
void revolve_z()
{
char c;
c=b[0];
b[0]=b[2];
b[2]=b[5];
b[5]=b[3];
b[3]=c;
}
void revolve(int n)
{
if(n==0)
revolve_x();
else if(n==1)
revolve_z();
else if(n==2)
{
revolve_z();
revolve_z();
}
else if(n==3)
{
revolve_z();
revolve_z();
revolve_z();
}
else if(n==4)
revolve_x();
}
int judge()
{
int t=0;
for(int i=0;i<6;i++)
{
for(int k=0;k<4;k++)
{
if(!strcmp(a,b))
return 1;
else
revolve_y();
}
revolve(i);
}
return t;
}
int main()
{
memset(str,0,sizeof(str));
while(cin>>str)
{
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
for(int i=0;i<6;i++)
a[i]=str[i];
for(int i=0;i<6;i++)
b[i]=str[i+6];
if(judge())
cout<<"TRUE"<<endl;
else
cout<<"FALSE"<<endl;
}
return 0;
}

** 本文迁移自我的CSDN博客,格式可能有所偏差。 **

昨天上毛概Ac了UVa-201之后开始想的,又是上毛概时Ac的。今天程序老师有事,除了晚自习毛概,一整天没课。上午打了会代码,中午宿舍聚餐,下午睡了会起来就 发现该上晚自习了。思路还是建数组,标记棋盘。代码写了很长,原本感觉运行时间也会很长,结果Run Time仅为0.009,应该是在代码中加了很多break和提 前return的缘故。虽然没超时,但感觉代码实在太长了,以后写代码尽量优化结构,让代码短一点。WA了一次因为没考虑一次落子夹住多枚的情况。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
#include<iostream>
#include<algorithm>
#include<cstring>
#include<iomanip>
#define maxn 10
using namespace std;
char a[maxn][maxn],x;
int n,w;
char now,nex;
void get_chessboard()
{
getchar();
memset(a,0,sizeof(a));
for(int i=0;i<8;i++)
gets(a[i]);
char c=getchar();
now='W';
nex='B';
if(c=='B')
swap(now,nex);
}
int is_legal_judge(int i,int j,int u)
{
int z=0;
if(a[i-1][j-1]==nex&&i-1>=0&&j-1>=0)
{
for(int k=2;i-k>=0&&j-k>=0;k++)
{
if(a[i-k][j-k]==nex)
continue;
else if(a[i-k][j-k]==now)
{
if(u)
{
for(int l=1;l<k;l++)
a[i-l][j-l]=now;
break;
}
return 1;
}
else
break;
}
}
if(a[i-1][j]==nex&&i-1>=0)
{
for(int k=2;i-k>=0;k++)
{
if(a[i-k][j]==nex)
continue;
else if(a[i-k][j]==now)
{
if(u)
{
for(int l=1;l<k;l++)
a[i-l][j]=now;
break;
}
return 1;
}
else
break;
}
}
if(a[i-1][j+1]==nex&&i-1>=0&&j+1<=8)
{
for(int k=2;i-k>=0&&j+k<=8;k++)
{
if(a[i-k][j+k]==nex)
continue;
else if(a[i-k][j+k]==now)
{
if(u)
{
for(int l=1;l<k;l++)
a[i-l][j+l]=now;
break;
}
return 1;
}
else
break;
}
}
if(a[i][j-1]==nex&&j-1>=0)
{
for(int k=2;j-k>=0;k++)
{
if(a[i][j-k]==nex)
continue;
else if(a[i][j-k]==now)
{
if(u)
{
for(int l=1;l<k;l++)
a[i][j-l]=now;
break;
}
return 1;
}
else
break;
}
}
if(a[i][j+1]==nex&&j+1<=8)
{
for(int k=2;j+k<=8;k++)
{
if(a[i][j+k]==nex)
continue;
else if(a[i][j+k]==now)
{
if(u)
{
for(int l=1;l<k;l++)
a[i][j+l]=now;
break;
}
return 1;
}
else
break;
}
}
if(a[i+1][j-1]==nex&&i+1<=8&&j-1>=0)
{
for(int k=2;i+k<=8&&j-k>=0;k++)
{
if(a[i+k][j-k]==nex)
continue;
else if(a[i+k][j-k]==now)
{
if(u)
{
for(int l=1;l<k;l++)
a[i+l][j-l]=now;
break;
}
return 1;
}
else
break;
}
}
if(a[i+1][j]==nex&&i+1<=8)
{
for(int k=2;i+k<=8;k++)
{
if(a[i+k][j]==nex)
continue;
else if(a[i+k][j]==now)
{
if(u)
{
for(int l=1;l<k;l++)
a[i+l][j]=now;
break;
}
return 1;
}
else
break;
}
}
if(a[i+1][j+1]==nex&&i+1<=8&&j+1<=8)
{
for(int k=2;i+k<=8&&j+k<=8;k++)
{
if(a[i+k][j+k]==nex)
continue;
else if(a[i+k][j+k]==now)
{
if(u)
{
for(int l=1;l<k;l++)
a[i+l][j+l]=now;
break;
}
return 1;
}
else
break;
}
}
return z;
}
int is_legal(int is_print)
{
int p=0,first=1;
for(int i=0;i<8;i++)
{
for(int j=0;j<8;j++)
{
if(a[i][j]=='-')
{
if(is_legal_judge(i,j,0))
{
if(is_print)
{
if(first)
first=0;
else
cout<<" ";
cout<<"("<<i+1<<","<<j+1<<")";
}
p++;
}
}
}
}
if(p&&is_print)
cout<<endl;
else if(!p&&is_print)
cout<<"No legal move."<<endl;
return p;
}
int cnt(char l)
{
int k=0;
for(int i=0;i<8;i++)
for(int j=0;j<8;j++)
if(a[i][j]==l)
k++;
return k;
}
void M()
{
int y,z;
cin>>y;
z=y%10;
y/=10;
y--;
z--;
if(!is_legal(0))
swap(now,nex);
is_legal_judge(y,z,1);
a[y][z]=now;
cout<<"Black - "<<setw(2)<<cnt('B')<<" White - "<<setw(2)<<cnt('W')<<endl;
swap(now,nex);
}
void print_chessboard()
{
for(int i=0;i<8;i++)
cout<<a[i]<<endl;
}
int main()
{
cin>>n;
while(n--)
{
get_chessboard();
char c;
while(cin>>c)
{
if(c=='L')
is_legal(1);
else if(c=='M')
M();
else if(c=='Q')
{
print_chessboard();
break;
}
}
if(n)
cout<<endl;
}
return 0;
}

** 本文迁移自我的CSDN博客,格式可能有所偏差。 **

从上午开始想的,下午上完机又改了改,晚上过的,题目不难,属于一看就有思路的那种,一次Ac。用了两个数组统计H、V两个方向线段,然后加个函数判断。上机课做完实 验题之后,敲代码时学长跟我提到了循环太多,不过好在这道题数据量不大。提交之后看,运行时间确实比平时提交的题长不少,以后做题还是尽量要减少循环层数。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include<iostream>
#include<cstring>
#define maxn 15
using namespace std;
int h[maxn][maxn],v[maxn][maxn];
int cnt[maxn];
char c;
int a,b,n,m;
int t=1,first=1;
void sr()
{
for(int i=0;i<m;i++)
{
cin>>c>>a>>b;
a--;
b--;
if(c=='H')
h[a][b]=1;
else if(c=='V')
v[b][a]=1;
}
}
void tj()
{
for(int i=0;i<n-1;i++)
{
for(int j=0;j<n-1-i;j++)
{
for(int k=0;k<n-1-i;k++)
{
int p=1;
for(int l=0;l<i+1;l++)
{
if(!p)
break;
if(!h[j][k+l])
p=0;
if(!h[j+i+1][k+l])
p=0;
if(!v[j+l][k])
p=0;
if(!v[j+l][k+i+1])
p=0;
}
if(p)
cnt[i]++;
}
}
}
}
void sc()
{
int k=0;
if(first)
first=0;
else
{
cout<<endl;
cout<<"**********************************"<<endl;
cout<<endl;
}
cout<<"Problem #"<<t<<endl;
cout<<endl;
for(int i=0;i<n;i++)
{
if(cnt[i])
cout<<cnt[i]<<" square (s) of size "<<i+1<<endl;
else
k++;
}
if(n==k)
cout<<"No completed squares can be found."<<endl;
t++;
}
int main()
{
while(cin>>n)
{
cin>>m;
memset(cnt,0,sizeof(cnt));
memset(h,0,sizeof(h));
memset(v,0,sizeof(v));
sr();
tj();
sc();
}
return 0;
}

** 本文迁移自我的CSDN博客,格式可能有所偏差。 **

残局能否将死的题,建了两个数组标记做的,WA了好多次,循环中的数出现过错误,还有一开始不知道中国象棋将只能直走,以为和国际象棋一样,可以斜着走,也错了好几次 。以后要注意循环的开始与结束去值是否正确。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
#include<iostream>
#include<cstdlib>
#include<cstring>
#define maxn 15
using namespace std;
int main()
{
char a[maxn][maxn],p[maxn][maxn],x;
int b,c,n,y,z;
cin>>n>>b>>c;
while(n&&b&&c)
{
b--;
c--;
int w=0;
memset(a,0,sizeof(a));
memset(p,0,sizeof(p));
for(int i=0;i<3;i++)
{
for(int j=3;j<6;j++)
{
if(abs(b-i)<=1&&c==j)
w++;
else if(b==i&&abs(c-j)<=1)
w++;
}
}
for(int i=0;i<n;i++)
{
cin>>x>>y>>z;
a[y-1][z-1]=x;
}
for(int i=0;i<maxn;i++)
{
for(int j=0;j<maxn;j++)
{
if(a[i][j]=='G')
{
for(int k=i-1;k>=0;k--)
{
if(!a[k][j])
p[k][j]='X';
else
{
p[k][j]='X';
break;
}
}
}
else if(a[i][j]=='R')
{
for(int k=i-1;k>=0;k--)
{
if(!a[k][j])
p[k][j]='X';
else
{
p[k][j]='X';
break;
}
}
for(int k=i+1;k<=maxn;k++)
{
if(!a[k][j])
p[k][j]='X';
else
{
p[k][j]='X';
break;
}
}
for(int k=j-1;k>=0;k--)
{
if(!a[i][k])
p[i][k]='X';
else
{
p[i][k]='X';
break;
}
}
for(int k=j+1;k<=maxn;k++)
{
if(!a[i][k])
p[i][k]='X';
else
{
p[i][k]='X';
break;
}
}
}
else if(a[i][j]=='H')
{
if(i-2>=0&&!a[i-1][j])
{
if(j-1>=0)
p[i-2][j-1]='X';
if(j+1<=maxn)
p[i-2][j+1]='X';
}
if(i+2<=maxn&&!a[i+1][j])
{
if(j-1>=0)
p[i+2][j-1]='X';
if(j+1<=maxn)
p[i+2][j+1]='X';
}
if(j-2>=0&&!a[i][j-1])
{
if(i-1>=0)
p[i-1][j-2]='X';
if(i+1<=maxn)
p[i+1][j-2]='X';
}
if(j+2<=maxn&&!a[i][j+1])
{
if(i-1>=0)
p[i-1][j+2]='X';
if(i+1<=maxn)
p[i+1][j+2]='X';
}
}
else if(a[i][j]=='C')
{
int t=0;
for(int k=i-1;k>=0;k--)
{
if(!t)
{
if(a[k][j])
t=1;
}
else
{
if(!a[k][j])
p[k][j]='X';
else
{
p[k][j]='X';
break;
}
}
}
t=0;
for(int k=i+1;k<=maxn;k++)
{
if(!t)
{
if(a[k][j])
t=1;
}
else
{
if(!a[k][j])
p[k][j]='X';
else
{
p[k][j]='X';
break;
}
}
}
t=0;
for(int k=j-1;k>=0;k--)
{
if(!t)
{
if(a[i][k])
t=1;
}
else
{
if(!a[i][k])
p[i][k]='X';
else
{
p[i][k]='X';
break;
}
}
}
t=0;
for(int k=j+1;k<=maxn;k++)
{
if(!t)
{
if(a[i][k])
t=1;
}
else
{
if(!a[i][k])
p[i][k]='X';
else
{
p[i][k]='X';
break;
}
}
}
}
}
}
for(int i=0;i<3;i++)
{
for(int j=3;j<6;j++)
{
if(p[i][j]=='X')
{
if(abs(b-i)<=1&&c==j)
w--;
else if(b==i&&abs(c-j)<=1)
w--;
}
}
}
if(!w)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
cin>>n>>b>>c;
}
return 0;
}

** 本文迁移自我的CSDN博客,格式可能有所偏差。 **

是道例题,编写个管理系统,类似于课本十二章的那个。自己写的代码运行样例正常,但提交WA。而且给了一半的代码,就又上网搜了例题原版代码。对比了输入与输出,一直 没找到错,目测是有个地方格式错了或者精度控制出现了问题。。 照着重敲一遍Ac了。。

PS:发现问题了,原本写的代码缓冲区出现了问题导致WA。。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#include<stdio.h>
#include<string.h>
#define maxn 1000
#define maxl 100
#define EPS 1e-5
int n;
char sid[maxn][maxl];
int cid[maxn];
char name[maxn][maxl];
int score[maxn][5];
int removed[maxn];
const char* course_name[]={"Chinese","Mathematics","English","Programming"};
int valid(int k)
{
for (int i=0;i<k;i++)
if(!removed[i])
if(!strcmp(sid[i],sid[k]))
return 0;
return 1;
}
void add()
{
while(1)
{
printf("Please enter the SID, CID, name and four scores. Enter 0 to finish.\n");
scanf("%s",sid[n]);
if(!strcmp(sid[n],"0"))
break;
scanf("%d%s%d%d%d%d",&cid[n],name[n],&score[n][0],&score[n][1],&score[n][2],&score[n][3]);
if(valid(n))
{
score[n][4]=score[n][0]+score[n][1]+score[n][2]+score[n][3];
n++;
}
else
printf("Duplicated SID.\n");
}
}
int rank(int k)
{
int r=0;
for(int i=0;i<n;i++)
if(!removed[i]&&score[i][4]>score[k][4])
r++;
return r+1;
}
void DQ (int isq)
{
char s[maxl];
while(1)
{
printf("Please enter SID or name. Enter 0 to finish.\n");
scanf("%s",s);
if(!strcmp (s, "0"))
break;
int r=0;
for(int i=0;i<n;i++)
if(!removed[i])
{
if(!strcmp(sid[i],s)||!strcmp(name[i],s))
{
if(isq)
printf("%d %s %d %s %d %d %d %d %d %.2f\n",rank(i),sid[i],cid[i],name[i],score[i][0],score[i][1],score[i][2],score[i][3],score[i][4],score[i][4]/4.0+EPS);
else
{
removed[i]=1;
r++;
}
}
}
if(!isq)
printf("%d student(s) removed.\n",r);
}
}
double get_course_stat(int c,int s,int* passed,int* failed)
{
int tot=0;
*passed=*failed=0;
for(int i=0;i<n;i++)
if(!removed[i]&&(!c||cid[i]==c))
{
tot+=score[i][s];
if(score[i][s]>=60)
(*passed)++;
else
(*failed)++;
}
return (double)tot/(double)(*passed+*failed);
}
void get_overall_stat(int c,int* cnt)
{
cnt[0]=cnt[1]=cnt[2]=cnt[3]=cnt[4]=0;
for(int i=0;i<n;i++)
if(!removed[i]&&(!c||cid[i]==c))
{
int k=0;
for(int j=0;j<4;j++)
if(score[i][j]>=60)
k++;
cnt[k]++;
}
}
void stat()
{
int c;
printf("Please enter class ID, 0 for the whole statistics.\n");
scanf("%d", &c);
for(int i=0;i<4;i++)
{
int passed,failed;
double avg=get_course_stat(c,i,&passed,&failed);
printf("%s\n",course_name[i]);
printf("Average Score: %.2f\n",avg+EPS);
printf("Number of passed students: %d\n",passed);
printf("Number of failed students: %d\n",failed);
printf("\n");
}
int cnt[5];
get_overall_stat(c,cnt);
printf("Overall:\n");
printf("Number of students who passed all subjects: %d\n",cnt[4]);
printf("Number of students who passed 3 or more subjects: %d\n",cnt[4]+cnt[3]);
printf("Number of students who passed 2 or more subjects: %d\n",cnt[4]+cnt[3]+cnt[2]);
printf("Number of students who passed 1 or more subjects: %d\n",cnt[4]+cnt[3]+cnt[2]+cnt[1]);
printf("Number of students who failed all subjects: %d\n",cnt[0]);
printf("\n");
}
int main()
{
while(1)
{
int choice;
printf("Welcome to Student Performance Management System (SPMS).\n");
printf("\n");
printf("1 - Add\n");
printf("2 - Remove\n");
printf("3 - Query\n");
printf("4 - Show ranking\n");
printf("5 - Show Statistics\n");
printf("0 - Exit\n");
printf("\n");
scanf("%d",&choice);
if(choice==0)
break;
if(choice==1)
add();
if(choice==2)
DQ(0);
if(choice==3)
DQ(1);
if(choice==4)
printf("Showing the ranklist hurts students' self-esteem. Don't do that.\n");
if(choice==5)
stat();
}
return 0;
}

** 本文迁移自我的CSDN博客,格式可能有所偏差。 **

是道算循环节的题,一开始完全没有思路,看c++的书写到大整数类模拟手算进行,再加上看了 @xuziye0327 的一篇关于数据处理的博客,有的思路。从昨天上 上机课开始写,到现在,总算过了,错了好多次,细节处理总是不到位。PS:总是不长记性,上机课忘换行WA一次,最早做完的成第二了;接着做这道题,又少换行错好几次 。。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include<iostream>
#include<cstring>
#define maxn 10000
using namespace std;
int main()
{
int a,b,i,j,k,l,t,z,y;
int n[maxn],m[maxn];
while(cin>>a>>b)
{
t=0,z=0;
if(!a)
goto END;
m[0]=a%b;
n[0]=a/b;
if(!m[0])
{
cout<<a<<"/"<<b<<" = "<<n[0]<<".(0)"<<endl;
cout<<" 1 = number of digits in repeating cycle"<<endl;
cout<<endl;
continue;
}
for(i=1;i<maxn;i++)
{
n[i]=m[i-1]*10/b;
m[i]=m[i-1]*10%b;
if(m[i]==0)
{
z=1;
goto END;
}
for(j=i-1;j>0;j--)
{
if(m[i]==m[j]&&n[i]==n[j])
{
for(k=j;k<=i;k++)
if(n[k])
break;
if(k!=i)
goto END;
}
}
}
END:
if(a==0)
{
cout<<a<<"/"<<b<<" = "<<"0.(0)"<<endl;
cout<<" 1 = number of digits in repeating cycle"<<endl;
}
else
{
if(z)
{
cout<<a<<"/"<<b<<" = "<<n[0]<<".";
for(k=1;k<i+1;k++)
cout<<n[k];
cout<<"(0)"<<endl;
cout<<" 1 = number of digits in repeating cycle"<<endl;
}
else
{
cout<<a<<"/"<<b<<" = "<<n[0]<<".";
for(k=1;k<j;k++)
cout<<n[k];
y=k-1;
cout<<"(";
if(i-j<=50-y)
for(k=j;k<=i-1;k++)
cout<<n[k];
else
{
for(k=j;k<j+50-y;k++)
cout<<n[k];
cout<<"...";
}
cout<<")"<<endl;
cout<<" "<<i-j<<" = number of digits in repeating cycle"<<endl;
}
}
cout<<endl;
}
return 0;
}

** 本文迁移自我的CSDN博客,格式可能有所偏差。 **

从见面会到现在十天过去了,该写点什么了。做到现在,总共过了21道,去掉1道不是书上的题(UVa-100),20道了,百题计划完成五分之一了。

从开学到现在,从一开始什么都不会,到现在好多题都能一次Ac,感觉自己成长挺快的。十一假期做ACM题,提升真的很大。见面会之后,做UVa的题,向学长请教,也学 到了很多。以后尽量保持住现在的状态吧。至于下一步的计划,尽量在11月初把c++的基础学完,然后再把编程书上之前没看的链表以后的看完,再来专心做UVa的题。期 间可能没有现在这么多时间来做题了。

最后再写写对将来的想法,也许以后会走编程这条路,也许这这只会是个爱好。但既然加了ACM协会,就尽力而为吧。

** 本文迁移自我的CSDN博客,格式可能有所偏差。 **