又来写题解辣~然而并不太清楚题目排列情况。。。不管辣先写起来~

T1:[bzoj1041]

题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1041

一个赤果果的数学题~~~

首先坐标轴上一定有四个,

最大公约数搞一下然后判断一下就可以啦,细节全部都在代码~

代码如下:

 var i,j,ans,d:longint;
t,r,m:int64;
function flag(x,y:longint):longint;
var t:longint;
begin
if (x<y) then
begin
t:=x;
x:=y;
y:=t;
end;
x:=x mod y;
if (x=) then exit(y) else exit(flag(x,y));
end;
begin
readln(r);
ans:=;
t:=*r;
for d:= to trunc(sqrt(t)) do
if (t mod d=) then
begin
for i:= to trunc(sqrt(r/d)) do
begin
j:=trunc(sqrt(t/d-i*i));
if (j=sqrt(t/d-i*i)) and (i<>j) and (flag(i,j)=) then inc(ans);
end;
for i:= to trunc(sqrt(d/)) do
begin
j:=trunc(sqrt(d-i*i));
if (j*j=d-i*i) and (i<>j) and (flag(i,j)=) then inc(ans);
end;
end;
ans:=ans*+;
writeln(ans);
end.

T2:[bzoj1042]

题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1042

又一个数学题hhh

先动态规划预处理,然后容斥原理就可以了。

代码如下:

 var i,j,k,l,tot,g:longint;
c,s:array[..] of longint;
f:array[..] of int64;
ans:int64;
function f1(x:longint):int64;
begin
if (x>=) then exit(f[x]) else exit();
end;
begin
fillchar(c,sizeof(c),);
fillchar(f,sizeof(f),);
readln(c[],c[],c[],c[],tot);
f[]:=;
for i:= to do
for j:=c[i] to do
f[j]:=f[j]+f[j-c[i]];
for i:= to tot do
begin
fillchar(s,sizeof(s),);
for j:= to do
read(s[j]);
readln(g);
ans:=f[g];
for j:= to do
ans:=ans-f1(g-(s[j]+)*c[j]);
for j:= to do
for k:=j+ to do
if (j<>k) then
ans:=ans+f1(g-(s[j]+)*c[j]-(s[k]+)*c[k]);
for j:= to do
for k:=j+ to do
for l:=k+ to do
if (j<>k) and (k<>l) and (j<>l) then
ans:=ans-f1(g-(s[j]+)*c[j]-(s[k]+)*c[k]-(s[l]+)*c[l]);
ans:=ans+f1(g-(s[]+)*c[]-(s[]+)*c[]-(s[]+)*c[]-(s[]+)*c[]);
writeln(ans);
end;
end.

(T3先留好坑。。。之后补)

T4:[bzoj1044]

题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1044

第一问就是NOIP2015的day2T1(把我坑死的QAQQQ),

第二问就是动态规划就行了。

代码如下:

 var n,m,i,j,k,ans,left,right,max,anss,s,now1,x,y:longint;
l,sl,ty:array[..] of longint;
f,f1:array[..,-..] of longint;
function tryit(x:longint):boolean;
var i,j,s,left,right:longint;
begin
i:=;
j:=;
now1:=;
while (i<n) do
begin
left:=i+;
right:=n;
i:=(left+right) div ;
while (right-left>) do
begin
if (sl[i]-sl[now1]<=x) then left:=i else right:=i;
i:=(left+right) div ;
end;
if (sl[right]-sl[now1]<=x) then i:=right else i:=left;
if (sl[n]-sl[now1]>x) then inc(j);
now1:=i;
end;
if (j>m) then exit(false) else exit(true);
end;
begin
read(n,m);
fillchar(l,sizeof(l),);
fillchar(sl,sizeof(sl),);
s:=;
max:=;
for i:= to n do
begin
read(l[i]);
sl[i]:=sl[i-]+l[i];
if (l[i]>max) then max:=l[i];
s:=s+l[i];
end;
left:=max;
right:=s;
ans:=(left+right) div ;
while (right-left>) do
begin
if not(tryit(ans)) then left:=ans else right:=ans;
ans:=(left+right) div ;
end;
ans:=right;
if tryit(left) then ans:=left;
write(ans,' ');
fillchar(f,sizeof(f),);
fillchar(ty,sizeof(ty),);
fillchar(f1,sizeof(f1),);
anss:=;
f[,]:=;
for i:= to n do
f1[,i]:=;
k:=;
for j:= to n do
begin
while (sl[j]-sl[k]>ans) do inc(k);
ty[j]:=k;
end;
for i:= to m+ do
begin
x:=i mod ;
y:=-x;
for j:= to n do
begin
f[y,j]:=(f1[x,j-]-f1[x,ty[j]-]+) mod ;
f1[y,j]:=(f[y,j]+f1[y,j-]) mod ;
end;
anss:=(anss+f[y,n]) mod ;
end;
writeln(anss);
end.

T5:[bzoj1045]

题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1045

这题。。。标准的组合数学嘛~~~

随便搞一下就粗来了。。。QAQ

辣么辣么多数学题QAQQQ

代码如下:

 var n,i,j:longint;
sum,ave,ans:int64;
a,p:array[..] of longint;
procedure qsort(lx,rx:longint);
var i,j,m,x:longint;
begin
i:=lx;
j:=rx;
m:=p[(i+j) div ];
repeat
while (p[i]<m) do inc(i);
while (p[j]>m) do dec(j);
if (i<=j) then
begin
x:=p[i];
p[i]:=p[j];
p[j]:=x;
inc(i);
dec(j);
end;
until (i>j);
if (i<rx) then qsort(i,rx);
if (j>lx) then qsort(lx,j);
end;
begin
readln(n);
fillchar(a,sizeof(a),);
fillchar(p,sizeof(p),);
sum:=;
for i:= to n do
begin
readln(a[i]);
sum:=sum+a[i];
end;
ave:=sum div n;
for i:= to n do
p[i]:=p[i-]-ave+a[i];
qsort(,n);
ans:=;
for i:= to n do
ans:=ans+abs(p[i]-p[n div +]);
writeln(ans);
end.

T6:[bzoj1054]

题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1054

QAQ这题是一个赤果果的BFS。。。

不对。。。

BFS要判重。。。这题判重都不要hhh

代码如下:

 type arr=array[..,..] of longint;
const modp=;
tx:array[..] of longint=(,-,,);
ty:array[..] of longint=(,,,-);
var i,j,k,s,t,s1,s2,rx,ry,swap,rh:longint;
q:array[..*] of arr;
mark:array[..*] of boolean;
step:array[..*] of longint;
ans:arr;
ch:char;
function hash(x:arr):longint;
var i,j,ans,now:longint;
begin
ans:=;
now:=;
for i:= to do
for j:= to do
begin
ans:=(ans+int64(now*x[i,j]));
now:=(now+now);
end;
exit(ans);
end;
begin
s:=;
t:=;
fillchar(q,sizeof(q),);
fillchar(ans,sizeof(ans),);
for i:= to do
begin
for j:= to do
begin
read(ch);
while (ch<>'') and (ch<>'') do read(ch);
q[,i,j]:=ord(ch)-;
end;
end;
for i:= to do
begin
for j:= to do
begin
read(ch);
while (ch<>'') and (ch<>'') do read(ch);
ans[i,j]:=ord(ch)-;
end;
end;
s1:=hash(q[s]);s2:=hash(ans);
mark[s1]:=true;
fillchar(step,sizeof(step),);
if (s1=s2) then writeln('') else
begin
while (s<t) do
begin
for i:= to do
for j:= to do
if (q[s,i,j]>) then
begin
for k:= to do
begin
rx:=i+tx[k];ry:=j+ty[k];
if (<=rx) and (rx<=) and (<=ry) and (ry<=) and (q[s,rx,ry]=) then
begin
swap:=q[s,i,j];q[s,i,j]:=q[s,rx,ry];q[s,rx,ry]:=swap;
rh:=hash(q[s]);
if not(mark[rh]) then
begin
if (rh=s2) then
begin
writeln(step[s]+);
halt;
end;
mark[rh]:=true;
q[t]:=q[s];
step[t]:=step[s]+;
inc(t);
end;
swap:=q[s,i,j];q[s,i,j]:=q[s,rx,ry];q[s,rx,ry]:=swap;
end;
end;
end;
inc(s);
end;
end;
end.

T7:[bzoj1055]

题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1055

又一个动态规划呢!

不过是一个记忆化搜索。。。

代码如下:

 const ch:array[..] of char=('W','I','N','G');
var i,j:longint;
f,flag:array[..,..,..] of boolean;
x:array[..,..,..] of char;
a:array[..] of longint;
s:string;
flagg:boolean;
function calc(x:char):longint;
begin
if (x='W') then exit()
else if (x='I') then exit()
else if (x='N') then exit()
else if (x='G') then exit();
end;
function f1(k,left,right:longint):boolean;
var i,j,t1,t2:longint;
begin
if flag[k,left,right] then exit(f[k,left,right]);
flag[k,left,right]:=true;
if (right=left) and (s[left]=ch[k]) then
begin
f[k,left,right]:=true;
exit(true);
end;
for i:= to a[k] do
begin
t1:=calc(x[k,i,]);
t2:=calc(x[k,i,]);
for j:=left to right- do
if f1(t1,left,j) and f1(t2,j+,right) then
begin
f[k,left,right]:=true;
exit(true);
end;
end;
f[k,left,right]:=false;
exit(false);
end;
begin
fillchar(a,sizeof(a),);
for i:= to do
read(a[i]);
readln;
fillchar(f,sizeof(f),false);
fillchar(flag,sizeof(flag),false);
for j:= to do
for i:= to a[j] do
readln(x[j,i,],x[j,i,]);
readln(s);
flagg:=false;
for i:= to do
if f1(i,,length(s)) then
begin
write(ch[i]);
flagg:=true;
end;
if not(flagg) then write('The name is wrong!');
writeln;
end.

(T8的坑也先留着。。。QAQQQ)

终于写完啦~~~撒花撒花~~~

最新文章

  1. SQL Server 中WITH (NOLOCK)浅析
  2. android tab选项卡的使用
  3. flume与kafka整合
  4. python Requests库在处理response时的一些陷阱
  5. 小甲鱼python视频弟十二讲(关于字符串的方法及注释下)
  6. 【转】SQL Server T-SQL高级查询
  7. 八大排序算法之五--交换排序—冒泡排序(Bubble Sort)
  8. (转)Spring中Bean的命名问题(id和name区别)及ref和idref之间的区别
  9. Spring的工作原理核心组件和应用
  10. zoj2729 Sum Up(模拟)
  11. SessionStateMode之SQL Server共享session
  12. AVL树的单双旋转操作
  13. python全栈学习--day9(函数初始)
  14. [LeetCode] Minimum Absolute Difference in BST 二叉搜索树的最小绝对差
  15. (七):C++分布式实时应用框架 2.0
  16. react 引用 layer (防忘记)
  17. Python中的短路计算
  18. 启动tomcat时报错:http-nio-8080-exec-10
  19. Python3-join()和split()
  20. npm包管理工具在一般项目中的应用方法

热门文章

  1. Linux分享笔记:查看帮助命令 &amp; 常用系统工作命令
  2. 用户和用户组以及 Linux 权限管理
  3. vue购物车的实现
  4. 第9课 文章模块分析及建表 Thinkphp5商城第四季
  5. MongDB之各种删除操作
  6. TS各个表 与 SECTION 的解析 CAS原理
  7. 排列算法汇总(下一个排列,全排列,第K个排列)
  8. 笔记-python-selenium,phantomjs
  9. Win7系统桌面便签怎么添加?
  10. hadoop完全分布式集群的搭建