BestCoder Round #66

T1 GTW likes math

传送门

http://acm.hdu.edu.cn/showproblem.php?pid=5595

题目大意

给定 f(x)=ax2+bx+c ,询问 [L,R] 上的最值

题解

暴力枚举 O(T(RL+1))

var
 t,a,b,c,l,r,e,f,i,j:longint;
begin
 readln(t);
 for i:=1 to t do
  begin
   readln(a,b,c,l,r);
   e:=l*l*a+l*b+c; f:=e;
   for j:=l+1 to r do
    begin
     if j*j*a+j*b+c>e then e:=j*j*a+j*b+c;
     if j*j*a+j*b+c<f then f:=j*j*a+j*b+c;
    end;
   writeln(e,' ',f);
  end;
end.

T2 GTW likes gt

传送门

http://acm.hdu.edu.cn/showproblem.php?pid=5596

题目大意

给定一个序列,序列中分为两种0和1,第i秒时,对于i前面和他不同种且能力值比它小的消灭掉,有 m ci在第 ci 秒,对 [1,ci] 的能力值+1,询问最后剩下的人数

题解

每个人如果被消灭,显然是后面的人把它消灭,那么我们从后往前分别记录0和1的最大值就好,对 [1,ci]+1 相当于对 [ci+1,n]1 ,即对最值 1 , O(N)

var
 w,x,y,z:array[0..50005]of longint;
 i,j,k,l:longint;
 t,n,m,ans,max1,max0:longint;
begin
 readln(t);
 for l:=1 to t do
  begin
   readln(n,m);
   for i:=1 to n do
    readln(x[i],y[i]);
   fillchar(z,sizeof(z),0);
   for i:=1 to m do
    begin readln(j); inc(z[j]); end;
   fillchar(w,sizeof(w),0); max0:=0; max1:=0;
   for i:=n downto 1 do
    begin
     if z[i]<>0 then begin dec(max0,z[i]); dec(max1,z[i]); end;
     if x[i]=0 then begin
      if y[i]<max1 then w[i]:=1;
      if y[i]>max0 then max0:=y[i];
     end;
     if x[i]=1 then begin
      if y[i]<max0 then w[i]:=1;
      if y[i]>max1 then max1:=y[i];
     end;
    end;
   ans:=0;
   for i:=1 to n do
    if w[i]=0 then inc(ans); writeln(ans);
  end;
end.

贴个 O(nm) 的暴力(这个暴力后来被另一个写暴力的哥们hack掉了,他一共hack掉6个人…)

var
 w,x,y,z:array[0..50005]of longint;
 i,j,k,l:longint;
 t,n,m,ans:longint;
begin
 readln(t);
 for l:=1 to t do
  begin
   readln(n,m);
   for i:=1 to n do
    readln(x[i],y[i]);
   fillchar(z,sizeof(z),0);
   for i:=1 to m do
    begin readln(j); inc(z[j]); end;
   fillchar(w,sizeof(w),0);
   for i:=1 to n do
    begin
     for j:=1 to i-1 do
      if (x[j]<>x[i])and(y[j]<y[i]) then w[j]:=1;
     if z[i]=0 then continue;
     for j:=1 to i do
      inc(y[j],z[i]);
    end;
   ans:=0;
   for i:=1 to n do
    if w[i]=0 then inc(ans); writeln(ans);
  end;
end.

T3 GTW likes function

传送门

http://acm.hdu.edu.cn/showproblem.php?pid=5597

题目大意

φ(fn(x))
fn(x)=f0(fn1(x))
f0(x)=xk=0(1)k22x2kCk2xk+1

题解

数学题一定要先打暴力找规律!!!
数学题一定要先打暴力找规律!!!
数学题一定要先打暴力找规律!!!
根据规律我们发现 f0(x)=x+1 ,所以显然 fn(x)=x+n+1,ans=φ(x+n+1),O(Tx+n+1)

var
 check:array[0..5000005]of boolean;
 prime:array[0..500005]of longint;
 i,j,k,l:longint;
 t,len:longint;
 n,x,ans:int64;
procedure prepare;
begin
 len:=0; n:=trunc(sqrt(1000000000000*2+1))+1;
 for i:=2 to n do
  begin
   if check[i]=false then begin inc(len); prime[len]:=i; end;
   for j:=1 to len do
    begin
     if i*prime[j]>n then break;
     check[i*prime[j]]:=true;
     if i mod prime[j]=0 then break;
    end;
  end;
end;

begin
 prepare;
 while not eof do
  begin
   readln(n,x); ans:=n+x+1; n:=ans;
   for i:=1 to len do
    if n mod prime[i]=0 then begin
     ans:=(ans div prime[i])*(prime[i]-1);
     while n mod prime[i]=0 do
      n:=n div prime[i];
    end;
   if n<>1 then ans:=(ans div n)*(n-1);
   writeln(ans);
  end;
end.

还是老老实实证一下…

T4 GTW likes czf

传送门

http://acm.hdu.edu.cn/showproblem.php?pid=5598

题目大意

给定区间 [L,R] G,T ,从 [L,R] 中任取1个数 x ,再从G,T中任取1个数 y ,询问x@y不同解的个数
定义 x@y=((x and y) or y) xor x

题解

x@y=((x and y) or y) xor x
x and y 其实是取出x,y都为1的部分为1
(x and y) or y 前一步取出为1的一定是y中也为1的所有还为1,前一步取出为0的一定是x,y中只有一个为1的,or上y就得到还是y
所以 x@y=y xor x
显然一个数xor不同数字得到的结果不同所以 ans=2(rl+1) ,那么问题转化为求重复数字
[L,R] 中两次分别取出 a,b ,使 G xor a=T xor b ,变下形我们得到 G xor T=a xor b ,也就是 [L,R] 中有多少对抑或后为 G xor T
参考http://blog.csdn.net/qwb492859377/article/details/50288611

T5 GTW likes tree

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值