jzoj C组 2017.1.14 比赛

来源:互联网 发布:何炅情商知乎 编辑:程序博客网 时间:2024/06/04 18:07

今天的比赛 100(枚举)+40(快排+暴力)+100(广搜)+30(暴力)=270

第一题

题目描述

小x想要申请英国剑桥大学,他准备了很长时间,在临走的一天,意外得知初审没有过,拒绝的理由竟然是体重!!!   小x很沮丧,于是,他做出了一个“丧心病狂”的决定:对他的单词书里包含“CAMBRIDGE”中任意一个字母的单词进行修改。具体方法是这样的:对于每个单词,删掉其中出现在“CAMBRIDGE”中的字母。

输入

有且仅有一行,包含一个有大写英文字母组成的单词(长度:3~100)。

输出

有且仅有一行,包含一个修改过的单词。

样例输入

LOVE

样例输出

LOV

数据范围限制

单词(长度:3~100)。


不用想暴力过


代码如下:

var    x,y:string;       a:array['A'..'Z']of boolean;       i:longint;begin  assign(input,'un.in');  assign(output,'un.out');  reset(input);;  rewrite(output);  readln(x);  y:='CAMBRIDGE';  fillchar(a,sizeof(a),true);  for i:=1 to length(y) do a[y[i]]:=false;  x:=upcase(x);  for i:=1 to length(x) do    if a[x[i]]=true then write(x[i]);  close(input);  close(output);end.

第二题

题目描述

    小x为了平复自己悲愤的心情,参加了F7赛车决赛的解说工作。作为一位优秀的主持人,他想要了解一下参加决赛的N位选手的情况。经过一番努力,他找到了各位选手前几站比赛的成绩。    决赛就要开始了,比赛规定:第一个到达终点的得到N分,第二个到达终点的得到N-1分,以此类推„„最后一个到达终点的得到1分。而且不会有两位选手同时到达终点。小x非常忙,所以他想请你帮他统计一下有多少选手有可能成为总冠军(之前的成绩+决赛成绩=总成绩,总成绩最高者为总冠军,总冠军可能有多位)。

输入

第一行一个正整数N(3 ≤ N ≤ 300 000),代表参加决赛的选手个数。

接下来N行,每行一个正整数Bi,代表第i位选手之前比赛的成绩。

输出

只有一行包含一个正整数,代表有可能成为总冠军的选手个数。

样例输入

Input1:

3
8
10
9

Input2:

5
15
14
15
12
14

样例输出

Output1:

3

Output2:

4

数据范围限制

3 ≤ N ≤ 300 000


先快排,再枚举如果i为第一,其他都是最坏的情况,能不能取得冠军。

代码如下:

var   x:array[0..300000]of longint;      m,n,i,j,k:longint;      bool:boolean;procedure qsort(l,r:longint);var  i,j,mid:longint;begin  if l>r then exit;  i:=l; j:=r;  mid:=x[(l+r) div 2];  repeat    while x[i]>mid do inc(i);    while x[j]<mid do dec(j);    if i<=j then      begin        x[0]:=x[i]; x[i]:=x[j]; x[j]:=x[0];        inc(i); dec(j);      end;  until i>j;  qsort(l,j);  qsort(i,r);end;begin  assign(input,'f7.in');  assign(output,'f7.out');  reset(input);  rewrite(output);  readln(n);  for i:=1 to n do readln(x[i]);  qsort(1,n);  m:=n;  for i:=n downto 1 do    begin      if x[i]=x[i+1] then        begin          if bool=false then dec(m);          continue;        end;      k:=1;      bool:=true;      for j:=1 to n do        if i<>j then          begin            if x[j]+k>x[i]+n then              begin                dec(m);                bool:=false;                break;              end            else inc(k);          end;      if bool=true then break;    end;  write(m);  close(input);  close(output);end.

第三题

题目描述

 话说小x神秘失踪了,最后发现是被外星人绑架了,幸好外星人目前还是在地球上活动,并且知道外星人不了解地球,幸好,小x身上有无线信号发送装置,我们终于确定了他的位置,必须赶快到那里去救他。 根据无线信号发送装置,我们确定出一张地图,为了尽快寻找到小x,组织把这个光荣而艰巨的任务便交给了你。编写程序,通过使用一张地图帮助研究所确定从研究所出发找到小x的最短距离。

输入
第一行为n(n<=1000)。
第二行为n*n的地图(其中0表示通路,1表示死路)。
最后两行每行有两个数字,分别表示研究所的坐标和小x信号所在的位置。

输出
一行一个数字k,表示从研究所出发找到小x的最短距离。

样例输入
10
0100110100
0001110010
1000000001
1000100011
0000101100
1000001100
1001010011
0000010100
0101010000
1001000001
1 7
10 2

样例输出
14

数据范围限制
(n<=1000)


直接码广搜过


代码如下:

const dx:array[1..4]of longint=(1,-1,0,0);      dy:array[1..4]of longint=(0,0,1,-1);var  a:array[-1..2000,-1..2000]of char;     n,b1,b2,e1,e2,l,tail:longint;     state:array[1..1000000,1..2]of longint;     father:array[1..2000000]of longint;procedure init;var i,j:longint;begin  readln(n);  for i:=1 to n do    begin      for j:=1 to n do read(a[i,j]);      readln;    end;  readln(b1,b2);  readln(e1,e2);end;function check(x,y:longint):boolean;begin  check:=true;  if a[x,y]='1' then check:=false;  if (x>n)or(y>n)or(y<1)or(x<1) then check:=false;end;procedure print(x:longint);begin  if x=0 then exit;  inc(l);  print(father[x]);end;procedure bfs;var head,i:longint;begin  head:=0; tail:=1; state[1,1]:=b1; state[1,2]:=b2; a[b1,b2]:='1';  father[1]:=0;  repeat    inc(head);    for i:=1 to 4 do      if check(state[head,1]+dx[i],state[head,2]+dy[i]) then        begin          inc(tail);          father[tail]:=head;          state[tail,1]:=state[head,1]+dx[i];          state[tail,2]:=state[head,2]+dy[i];          a[state[tail,1],state[tail,2]]:='1';          if (state[tail,1]=e1)and(state[tail,2]=e2) then            begin              print(father[tail]);              tail:=0;              writeln(l);              halt;            end;        end;  until head>=tail;end;begin  assign(input,'findn.in');  assign(output,'findn.out');  reset(input);  rewrite(output);  init;  bfs;  close(input);  close(output);end.

第四题

题目描述
小x的好朋友小y给他出了一道难题,他想让小x在一个矩阵中找到一个子矩阵,使它的和最大。小x希望你能帮他解决这个问题。

输入
第一行一个正整数N,M。
以下N行,每行M个整数。

输出
有且仅有一行,包含一个数,表示所求的最大的和。
保证结果在longint范围内。

样例输入
3 3
2 -1 1
-3 2 -2
0 1 1

样例输出
3

数据范围限制
【数据范围】
对于30%的数据:1<=N,M<=50
对于60%的数据:1<=N,M<=100
对于100%的数据:1<=N,M<=500


将每一段的值求出来,再枚举每一种情况。


代码如下:

var   n,m,i,j,k,max,ans,min:longint;      a,b:array[0..501,0..501]of longint;begin  assign(input,'mpro.in');  assign(output,'mpro.out');  reset(input);  rewrite(output);  readln(n,m);  for i:=1 to n do    begin      for j:=1 to m do        begin          read(a[i,j]);          b[i,j]:=a[i,j]+b[i-1,j]+b[i,j-1]-b[i-1,j-1];        end;      readln;    end;  ans:=0;  for i:=0 to n-1 do    for j:=i+1 to n do      begin        min:=0;        max:=0;        for k:=1 to m do          begin            max:=b[j,k]-b[i,k]-min;            if max>ans then ans:=max;            if b[j,k]-b[i,k]<min then min:=b[j,k]-b[i,k];          end;      end;  write(ans);  close(input);  close(output);end.
1 0
原创粉丝点击