205 条题解
-
0kw1023 LV 8 @ 2009-07-23 16:08:54
#include
int main(void)
{
int a[23][10][10],i,j,k,n,s1,s2,g1,g2,check[23]={0};
s1=0,s2=0,g1=1,g2=1;
scanf("%d",&n);
for(k=1;k -
02009-07-21 00:17:07@
编译通过...
├ 测试数据 01:答案正确... 0ms
├ 测试数据 02:答案正确... 0ms
├ 测试数据 03:答案正确... 0ms
├ 测试数据 04:答案正确... 0ms
├ 测试数据 05:答案正确... 0ms
├ 测试数据 06:答案正确... 0ms
├ 测试数据 07:答案正确... 0ms
├ 测试数据 08:答案正确... 0ms
├ 测试数据 09:答案正确... 0ms
├ 测试数据 10:答案正确... 0ms
---|---|---|---|---|---|---|---|-
Accepted 有效得分:100 有效耗时:0msvar used:array[0..13]of 0..1; a:array[0..100,0..100]of integer;
i,n:longint;
procedure doit;
var j,k:longint;
begin
for j:=1 to 9 do
for k:=1 to 9 do read(a[j,k]);
for j:=1 to 9 do
begin
for k:=1 to 9 do used[k]:=0;
for k:=1 to 9 do used[a[j,k]]:=1;
for k:=1 to 9 do if used[k]=0 then
begin
writeln('Wrong');
exit;
end;
end;
for j:=1 to 9 do
begin
for k:=1 to 9 do used[k]:=0;
for k:=1 to 9 do used[a[k,j]]:=1;
for k:=1 to 9 do if used[k]=0 then
begin
writeln('Wrong');
exit;
end;
end;
for k:=1 to 9 do used[k]:=0;
for j:=1 to 3 do
beginfor k:=1 to 3 do used[a[j,k]]:=1;
end;
for k:=1 to 9 do if used[k]=0 then
begin
writeln('Wrong');
exit;
end;
for k:=1 to 9 do used[k]:=0;
for j:=4 to 6 do
beginfor k:=1 to 3 do used[a[j,k]]:=1;
end;
for k:=1 to 9 do if used[k]=0 then
begin
writeln('Wrong');
exit;
end;
for k:=1 to 9 do used[k]:=0;
for j:=7 to 9 do
beginfor k:=1 to 3 do used[a[j,k]]:=1;
end;
for k:=1 to 9 do if used[k]=0 then
begin
writeln('Wrong');
exit;
end;
for k:=1 to 9 do used[k]:=0;
for j:=1 to 3 do
beginfor k:=4 to 6 do used[a[j,k]]:=1;
end;
for k:=1 to 9 do if used[k]=0 then
begin
writeln('Wrong');
exit;
end;
for k:=1 to 9 do used[k]:=0;
for j:=4 to 6 do
beginfor k:=4 to 6 do used[a[j,k]]:=1;
end;
for k:=1 to 9 do if used[k]=0 then
begin
writeln('Wrong');
exit;
end;
for k:=1 to 9 do used[k]:=0;
for j:=7 to 9 do
beginfor k:=4 to 6 do used[a[j,k]]:=1;
end;
for k:=1 to 9 do if used[k]=0 then
begin
writeln('Wrong');
exit;
end;
for k:=1 to 9 do used[k]:=0;
for j:=1 to 3 do
beginfor k:=7 to 9 do used[a[j,k]]:=1;
end;
for k:=1 to 9 do if used[k]=0 then
begin
writeln('Wrong');
exit;
end;
for k:=1 to 9 do used[k]:=0;
for j:=4 to 6 do
beginfor k:=7 to 9 do used[a[j,k]]:=1;
end;
for k:=1 to 9 do if used[k]=0 then
begin
writeln('Wrong');
exit;
end;
for k:=1 to 9 do used[k]:=0;
for j:=7 to 9 do
beginfor k:=7 to 9 do used[a[j,k]]:=1;
end;
for k:=1 to 9 do if used[k]=0 then
begin
writeln('Wrong');
exit;
end;
writeln('Right');
end;
begin
readln(n);
for i:=1 to n do
doit;
end. -
02009-07-18 14:10:01@
激动呀 (≧▽≦)/
一次AC了 纪念113题AC 总算2星半了
编译通过...
├ 测试数据 01:答案正确... 0ms
├ 测试数据 02:答案正确... 0ms
├ 测试数据 03:答案正确... 0ms
├ 测试数据 04:答案正确... 0ms
├ 测试数据 05:答案正确... 0ms
├ 测试数据 06:答案正确... 0ms
├ 测试数据 07:答案正确... 0ms
├ 测试数据 08:答案正确... 0ms
├ 测试数据 09:答案正确... 0ms
├ 测试数据 10:答案正确... 0ms
---|---|---|---|---|---|---|---|-
Accepted 有效得分:100 有效耗时:0msprogram p1335;
var n,k,i,j,t1,t2:longint;
t:boolean;
a:array[1..10,1..10] of integer;
num:array[1..10] of integer;begin
readln(n);for k:=1 to n do
beginfillchar(a,sizeof(a),0);
for i:=1 to 9 do
begin
for j:=1 to 9 do read(a);
readln;
end;
readln;t:=true;
if t then
for i:=1 to 9 do
begin
fillchar(num,sizeof(num),0);
for j:=1 to 9 do num[a]:=1;
for j:=1 to 9 do if num[j]=0 then t:=false;
if not(t) then break;
end;if t then
for j:=1 to 9 do
begin
fillchar(num,sizeof(num),0);
for i:=1 to 9 do num[a]:=1;
for i:=1 to 9 do if num[i]=0 then t:=false;
if not(t) then break;
end;i:=1;
if t then
while i -
02009-07-17 08:26:38@
编译通过...
├ 测试数据 01:答案正确... 0ms
├ 测试数据 02:答案正确... 0ms
├ 测试数据 03:答案正确... 0ms
├ 测试数据 04:答案正确... 0ms
├ 测试数据 05:答案正确... 0ms
├ 测试数据 06:答案正确... 0ms
├ 测试数据 07:答案正确... 0ms
├ 测试数据 08:答案正确... 0ms
├ 测试数据 09:答案正确... 0ms
├ 测试数据 10:答案正确... 0ms
---|---|---|---|---|---|---|---|-
Accepted 有效得分:100 有效耗时:0msvar
n,i,j,p,q,w,k:longint;
f:boolean;
s:array[0..1000]of integer;
a:array[1..9,1..9]of integer;
begin
readln(n);
for k:=1 to n do
begin
for i:=1 to 9 do
begin
for j:=1 to 9 do
read(a);
readln;
end;
fillchar(s,sizeof(s),0);
f:=true;
for i:=1 to 9 do
begin
for j:=1 to 9 do
for q:=1 to 9 do
if a=q then s[q]:=s[q]+1;
for q:=1 to 8 do
if s[q]s[q+1] then begin f:=false;break;end;
if not f then break;
end;
for j:=1 to 9 do
begin
for i:=1 to 9 do
for q:=1 to 9 do
if a=q then s[q]:=s[q]+1;
for q:=1 to 8 do
if s[q]s[q+1] then begin f:=false;break;end;
if not f then break;
end;
for i:=1 to 3 do
for p:=1 to 3 do
begin
for j:=-1 to 1 do
for q:=-1 to 1 do
begin
for w:=1 to 9 do
if a=w then s[w]:=s[w]+1;
end;
for w:=1 to 8 do
if s[w]s[w+1] then begin f:=false;break;end;
if not f then break;
end;
if f then writeln('Right')
else writeln('Wrong');
end;
end.交了2次。。。。。
第2个数独做之前要初始一些东西
晕 -
02009-07-12 14:39:03@
水题
89 lines -
02009-07-11 15:42:25@
终于过了 题意理解错了,以为是任何一个3*3都要检查,再看发现只用检查9个
对于水题就多做一点工作 这么麻烦的题,少写几行是个技术活 我想用集合直接判断是否相等应该比较简单,结果整50行。。。另外
1.用read不用考虑换行问题,回车符直接省略掉 不过有的题好像必须readln
2.不少人开布尔数组,不太好写,数据这么小,还是集合好
3.有人用1~9的和是多少,积是多少判断,不论能否AC,这种算法有反例存在 还有人用上了方差(有创意。。。)仍有反例,但考试的时候可以拼一下RP,如果需要的话(哈希就这么来的)
4.位运算怎么写? 谁教我一下? -
02009-06-11 20:46:42@
千万注意mod!
-
02009-06-08 13:54:11@
"没有读完一个数独的数而又已经能判断其为‘WRONG’时,直接跳到第2个数独,可能产生第2个和第9个测试数据错误"
---|-感谢zhengshuyuan牛的指点! 40行AC3*3的格用的 z[(i+2) div 3,(j+2) div 3,a] 貌似会慢...不过还是0ms
-
02009-05-29 10:37:29@
我AC率……打错了一个地方写成了fillchar(f2,sizeof(f3),0)……,囧了个80……
{——————————————————————————————}
编译通过...
├ 测试数据 01:答案正确... 0ms
├ 测试数据 02:答案正确... 0ms
├ 测试数据 03:答案正确... 0ms
├ 测试数据 04:答案正确... 0ms
├ 测试数据 05:答案正确... 0ms
├ 测试数据 06:答案正确... 0ms
├ 测试数据 07:答案正确... 0ms
├ 测试数据 08:答案正确... 0ms
├ 测试数据 09:答案正确... 0ms
├ 测试数据 10:答案正确... 0ms
---|---|---|---|---|---|---|---|-
Accepted 有效得分:100 有效耗时:0msconst
p:array[1..9,1..9]of integer=
((1,1,1,2,2,2,3,3,3),
(1,1,1,2,2,2,3,3,3),
(1,1,1,2,2,2,3,3,3),
(4,4,4,5,5,5,6,6,6),
(4,4,4,5,5,5,6,6,6),
(4,4,4,5,5,5,6,6,6),
(7,7,7,8,8,8,9,9,9),
(7,7,7,8,8,8,9,9,9),
(7,7,7,8,8,8,9,9,9));
var
n,i,j,k:integer;
a,f1,f2,f3:array[1..9,1..9]of integer;
v:boolean;
begin
readln(n);
for k:=1 to n do
begin
v:=true;
fillchar(f1,sizeof(f1),0);
fillchar(f2,sizeof(f2),0);
fillchar(f3,sizeof(f3),0);
for i:=1 to 9 do
for j:=1 to 9 do
read(a);
for i:=1 to 9 do
for j:=1 to 9 do
begin
inc(f1[i,a]);
inc(f2[j,a]);
inc(f3[p,a]);
end;
for i:=1 to 9 do
for j:=1 to 9 do
if f11 then
begin v:=false; break; end;
for i:=1 to 9 do
for j:=1 to 9 do
if f21 then
begin v:=false; break; end;
for i:=1 to 9 do
for j:=1 to 9 do
if f31 then
begin v:=false; break; end;
if v then writeln('Right') else writeln('Wrong');
end;Flag
Accepted
题号
P1335
类型(?)
其它
通过
1295人
提交
2996次
通过率
43%
难度
1提交 讨论 题解
编译通过...
├ 测试数据 01:答案正确... 0ms
├ 测试数据 02:答案错误...
├ 标准行输出
├ 错误行输出
├ 测试数据 03:答案正确... 0ms
├ 测试数据 04:答案正确... 0ms
├ 测试数据 05:答案正确... 0ms
├ 测试数据 06:答案正确... 0ms
├ 测试数据 07:答案正确... 0ms
├ 测试数据 08:答案正确... 0ms
├ 测试数据 09:答案错误...
├ 标准行输出
├ 错误行输出
├ 测试数据 10:答案正确... 0ms为什么错了两个点……
{————————————————————————————}
const
p:array[1..9,1..9]of integer=
((1,1,1,2,2,2,3,3,3),
(1,1,1,2,2,2,3,3,3),
(1,1,1,2,2,2,3,3,3),
(4,4,4,5,5,5,6,6,6),
(4,4,4,5,5,5,6,6,6),
(4,4,4,5,5,5,6,6,6),
(7,7,7,8,8,8,9,9,9),
(7,7,7,8,8,8,9,9,9),
(7,7,7,8,8,8,9,9,9));
var
n,i,j,k:integer;
a,f1,f2,f3:array[1..9,1..9]of integer;
v:boolean;
begin
readln(n);
for k:=1 to n do
begin
v:=true;
fillchar(f1,sizeof(f1),0);
fillchar(f2,sizeof(f2),0);
fillchar(f2,sizeof(f3),0);
for i:=1 to 9 do
for j:=1 to 9 do
read(a);
for i:=1 to 9 do
for j:=1 to 9 do
begin
inc(f1[i,a]);
inc(f2[j,a]);
inc(f3[p,a]);
end;
for i:=1 to 9 do
for j:=1 to 9 do
if f11 then
begin v:=false; break; end;
for i:=1 to 9 do
for j:=1 to 9 do
if f21 then
begin v:=false; break; end;
for i:=1 to 9 do
for j:=1 to 9 do
if f31 then
begin v:=false; break; end;
if v then writeln('Right') else writeln('Wrong');
end;
end. -
02009-05-23 15:47:28@
编译通过...
├ 测试数据 01:答案正确... 0ms
├ 测试数据 02:答案正确... 0ms
├ 测试数据 03:答案正确... 0ms
├ 测试数据 04:答案正确... 0ms
├ 测试数据 05:答案正确... 0ms
├ 测试数据 06:答案正确... 0ms
├ 测试数据 07:答案正确... 0ms
├ 测试数据 08:答案正确... 0ms
├ 测试数据 09:答案正确... 0ms
├ 测试数据 10:答案正确... 0ms
---|---|---|---|---|---|---|---|-
Accepted 有效得分:100 有效耗时:0ms
for(i=1;i -
02009-08-29 09:39:10@
时格半年 终于AC了!!!!!!!
var
a:array[1..9,1..9] of integer;
bo:boolean;
n,i,j,k:integer;
procedure judge(a,b,c,d,e,f,g,h,l:integer);
begin
if [a,b,c,d,e,f,g,h,l][1..9] then bo:=false;
end;
begin
readln(n);
for i:=1 to n do
begin
bo:=true;
for j:=1 to 9 do
for k:=1 to 9 do read(a[j,k]);
for j:=1 to 9 do
begin
if not bo then break;
judge(a[j,1],a[j,2],a[j,3],a[j,4],a[j,5],a[j,6],a[j,7],a[j,8],a[j,9]);
if not bo then break;
judge(a[1,j],a[2,j],a[3,j],a[4,j],a[5,j],a[6,j],a[7,j],a[8,j],a[9,j]);
end;
for j:=0 to 2 do
for k:=0 to 2 do
begin
if not bo then break;
judge(a[3*j+1,3*k+1],a[3*j+2,3*k+1],a[3*j+3,3*k+1],a[3*j+1,3*k+2],a[3*j+2,3*k+2],a[3*j+3,3*k+2],a[3*j+1,3*k+3],a[3*j+2,3*k+3],a[3*j+3,3*k+3]);
end;
if bo then writeln('Right')
else writeln('Wrong');
end;
end. -
02009-03-31 20:52:37@
编译通过...
├ 测试数据 01:答案正确... 0ms
├ 测试数据 02:答案正确... 0ms
├ 测试数据 03:答案正确... 0ms
├ 测试数据 04:答案正确... 0ms
├ 测试数据 05:答案正确... 0ms
├ 测试数据 06:答案正确... 0ms
├ 测试数据 07:答案正确... 0ms
├ 测试数据 08:答案正确... 0ms
├ 测试数据 09:答案正确... 0ms
├ 测试数据 10:答案正确... 0ms
---|---|---|---|---|---|---|---|-
Accepted 有效得分:100 有效耗时:0ms
program ma;
var
n,i,j,k,s:longint;
t:boolean;
a:array[1..10,1..10] of longint;
b:array[1..10] of longint;
begin
readln(n);
for i:=1 to n do
begin
for j:=1 to 9 do
for k:=1 to 9 do
read(a[j,k]);
readln;
readln;
t:=true;
j:=1;
k:=1;
while j -
02009-03-20 09:44:57@
program P1335;
var
f:boolean;
a:array[1..9,1..9] of integer;
n,i:integer;
procedure init;
var
i,j:integer;
begin
f:=true;
for i:=1 to 9 do
begin
for j:=1 to 9 do
read(a);
readln;
end;
end;procedure pd(a1,a2,b1,b2:integer);
var
b:array[1..9] of boolean;
i,j:integer;
begin
fillchar(b,sizeof(b),true);
for i:=a1 to a2 do
for j:=b1 to b2 do
if b[a] then b[a]:=false else
begin
f:=false;
exit;
end;
end;procedure tries;
var
i:longint;
begin
for i:=1 to 9 do
begin
pd(1,9,i,i);
if not f then exit;
pd(i,i,1,9);
if not f then exit;
end;
pd(1,3,1,3);if not f then exit;
pd(1,3,4,6);if not f then exit;
pd(1,3,7,9);if not f then exit;
pd(4,6,1,3);if not f then exit;
pd(4,6,4,6);if not f then exit;
pd(4,6,7,9);if not f then exit;
pd(7,9,1,3);if not f then exit;
pd(7,9,4,6);if not f then exit;
pd(7,9,7,9);if not f then exit;
end;begin
readln(n);
for i:=1 to n-1 do
begin
init;
tries;
if f then writeln('Right') else writeln('Wrong');
readln;
end;
init;
tries;
if f then writeln('Right') else writeln('Wrong');
end. -
02009-03-17 20:06:48@
#include
#include
int ok[10];
int a[10][10];
int i,j,k,n,m,flag;
void bezero(){
int x;
for (x=1;x -
02009-03-03 21:49:24@
编译通过...
├ 测试数据 01:答案正确... 0ms
├ 测试数据 02:答案正确... 0ms
├ 测试数据 03:答案正确... 0ms
├ 测试数据 04:答案正确... 0ms
├ 测试数据 05:答案正确... 0ms
├ 测试数据 06:答案正确... 0ms
├ 测试数据 07:答案正确... 0ms
├ 测试数据 08:答案正确... 0ms
├ 测试数据 09:答案正确... 0ms
├ 测试数据 10:答案正确... 0ms
---|---|---|---|---|---|---|---|-
Accepted 有效得分:100 有效耗时:0ms
用一个数组表示每行每列数的个数的情况,再用循环判断是否每一位上的数都为1,如不为1,退出循环,输出Wrong;如为1则清零准备下一次计数。
九宫图用if判断==45即OK!(交了6次+,总结的经验)
我的题解 - My Solution :
#include "stdio.h"
int main()
{
int n,a[10][10],x,i,j,s[10]={0},check[20]={0};
scanf("%d",&n);
for(x=1;x -
02009-02-28 20:01:00@
var
i,j,k,x,n,sum,l:integer;
f1:array [1..9,1..9] of integer;
r:array [1..9,1..9] of integer;
function check:boolean;
b egin
fillchar(r,sizeof(r),0);
for i:=1 to 9 do
for j:=1 to 9 do
read(r);
sum:=45;
for i:=1 to 9 do
begin
if sum 45 then exit(false);
sum:=0;
for j:=1 to 9 do
begin
sum:=sum+r;
end;
end;
i:=1;
repeat
begin
if sum45 then exit(false);
sum:=0;
for j:=i to i+2 do
for k:=i to i+2 do
sum:=sum+r[j,k];
end;
inc(i,3);
until i>=9;
exit(true);
end;begin
readln(n);
for l:=1 to n do
if check then writeln('Right')
else writeln('Wrong');
end. -
02009-02-20 12:37:06@
#include
#include
int main (){
int n;
scanf ("%d",&n);
int a[10][10],i,t,j,k,b[10];
for (i=0;i -
02009-02-19 20:57:05@
总之一句话,出题人太善良了
program shuduyanzheng;
const dx:array[1..3] of integer=(2,5,8);
dy:array[1..3] of integer=(2,5,8);
type ss=set of 1..9;
var a:array[1..9,1..9] of integer;
i,j,k,l,n,m:integer;
yy:boolean;
s:ss;function try1(x,y:integer):boolean;
var i,j:integer;
begin
s:=[];try1:=false;
for i:=x-1 to x+1 do
for j:=y-1 to y+1 do
if a in s then
begin
try1:=true;
exit;
end else s:=s+[a] ;end;
function try2(x:integer):boolean;
var i:integer;
begin
s:=[];
try2:=false;
for i:=1 to 9 do
if a[x,i] in s then
begin
try2:=true;
exit;
end else s:=s+[a[x,i]];
end;function try3(y:integer):boolean;
var i:integer;
begin
s:=[];
try3:=false;
for i:=1 to 9 do
if a in s then
begin
try3:=true;
exit;
end else s:=s+[a];
end;begin
readln(n);
for k:=1 to n do
begin
yy:=false;
for i:=1 to 9 do
for j:=1 to 9 do
read(a);
for i:=1 to 9 do
if try2(i) or try3(i) then begin yy:=true ;break end;
if not yy then
for i:=1 to 3 do
for j:=1 to 3 do
if try1(dx[i],dy[j]) then begin
yy:=true;
break;
end;
if yy=true then writeln('Wrong')
else writeln('Right');
end;
end. -
02009-02-11 09:46:34@
#include
using namespace std;
int map[9][9],n;
bool check[10],flag;
int main(){
int n,i,j,a,b;
cin>>n;
while (n>0){
n--;
for (i=0;imap[i][j];
flag=0;
for (j=0;j -
02009-02-10 22:15:52@
Var
xi,xj,n,q,i,j,data:integer;
hang,lie:array[1..9,1..9] of boolean;
ans:array[1..20] of boolean;
bool:boolean;
k:array[1..9] of integer;
Begin
readln(n);
for q:=1 to n do
begin
fillchar(hang,sizeof(hang),1);
fillchar(lie,sizeof(hang),1);
fillchar(k,sizeof(k),0);
bool:=true;
for i:=1 to 9 do
begin
if bool then
for j:=1 to 9 do
begin
read(data);
if i in[1..3] then xi:=0;if i in [4..6] then xi:=3;if i in [7..9] then xi:=6;
if j in[1..3] then xj:=1;if j in [4..4] then xj:=2;if j in [7..9] then xj:=3;
inc(k[xi+xj],data);
if hang then hang:=false
else bool:=false;
if lie[j,data] then lie[j,data]:=false
else bool:=false;
end;
readln;
end;
for i:=1 to 9 do if k[i]45 then bool:=false;
if bool then ans[q]:=true
else ans[q]:=false;
readln;
end;
for i:=1 to n do
if ans[i] then writeln('Right')
else writeln('Wrong');
End.行列预处理,每个九宫格累加,最后判断是否9个九宫格都=45.搞定~
一次ac~