142 条题解
-
0xtx123 LV 8 @ 2015-09-06 18:56:40
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
struct node{
int x,y,c;
};
node h[500];
int n,m,t,sum,tot,px,py,ans;
inline int comp(node a,node b)
{
return a.c>b.c;
}
inline int dis(node a,node b)
{
return abs(a.x-b.x)+abs(a.y-b.y);
}
int main()
{
scanf("%d%d%d",&n,&m,&t);
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++){
int x;
scanf("%d",&x);
if(x) h[++tot].x=j,h[tot].y=i,h[tot].c=x;
}
sort(h+1,h+tot+1,comp);
sum=h[1].y+1;ans=h[1].c;
if(sum+h[1].y>t){
printf("0");
return 0;
}
for(int i=2;i<=tot;i++)
if(sum+dis(h[i-1],h[i])+1+h[i].y>t) break;
else sum+=dis(h[i-1],h[i])+1,ans+=h[i].c;
printf("%d",ans);
} -
02015-08-24 16:05:27@
此题不用数组,优先队列秒杀
//l函数
return abs(x0-x1)+abs(y0-y1);
//main函数,point是自定义的结构体,想必大家都会,x,y表示坐标,v表示花生数量
int n,m,k; cin>>n>>m>>k;
for (int i=1;i<=n;++i) {
for (int j=1;j<=m;++j) {
int v; cin>>v;
if (v) q.push(point(i,j,v));
}
}
int t=q.top().x+1,nowx=q.top().x,nowy=q.top().y;
if (t+nowx<=k) {
ans+=q.top().v; q.pop();
}
int o=q.size();
for (int i=0;i<o;++i) {
t+=l(nowx,nowy,q.top().x,q.top().y)+1;
nowx=q.top().x; nowy=q.top().y;
if (t+nowx>k) break;
ans+=q.top().v; q.pop();
}
cout<<ans;
return 0; -
02015-05-15 10:35:17@
#include <stdio.h>
#include <math.h>
#include <stdlib.h>int main(int argc, char** argv) {
int m, n, k;
scanf("%d%d%d", &m, &n, &k);
int a[m][n];
for(int i = 0; i < m; ++i) {
for(int j = 0; j < n; ++j) {
scanf("%d", &a[i][j]);
}
}
int h = 0, l = 0;
int h1 = 0, l1 = 0;
int bs = 0;
int gs = 0;
while(true) {
int max = 0;
for(int i = 0; i < m; ++i) {
for(int j = 0; j < n; ++j) {
if(a[i][j] > max) {
max = a[i][j];
h1 = i;
l1 = j;
}
}
}
a[h1][l1] = 0;
if(gs == 0) {
bs += abs(h1 - h + 1);
} else {
bs += abs(h1 - h);
}
if(gs != 0) {
bs += abs(l1 - l);
}
++bs;
gs += max;
int js = bs;
js += h1 + 1;
if(js == k) {
printf("%d", gs);
break;
}
if(js > k) {
printf("%d", gs - max);
break;
}
h = h1;
l = l1;
max = 0;
}
return 0;
} -
02015-03-18 21:21:41@
#include<iostream>
#include<queue>
#include<cmath>
using namespace std;int A[100][100];
struct data
{
int x;
int y;
int c;
};struct cmp
{
bool operator()(data a,data b)
{ return a.c<b.c;}
};int main()
{
int M,N,K,ans=0,time=1;
cin>>M>>N>>K;priority_queue<data,vector<data>,cmp> q;
data temp;
for(int i=1;i<=M;i++)
for(int j=1;j<=N;j++)
{ cin>>A[i][j];if(A[i][j]>0)
{temp.x=i;
temp.y=j;
temp.c=A[i][j];
q.push(temp);
}
}int last_x,last_y;
bool fir=true;while(!q.empty())
{
data temp=q.top();
int x=temp.x,y=temp.y;
q.pop();if(fir)
{
last_x=1,last_y=y;
fir=false;
}int seg1=x; //back time
int seg2=abs(x-last_x)+abs(y-last_y); //distance time
if(K>=time+seg1+seg2+1)
{
time=time+seg2+1;
ans+=temp.c;
last_x=x;
last_y=y;
}
else break;
}
cout<<ans<<endl;return 0;
} -
02015-02-28 11:04:11@
program exam1120;
var m,n,k,i,j,s,t,x,r,time,num,l,p:longint;
a:array[1..10000,1..30]of longint;
b,c,d:array[1..10000]of longint;
begin
readln(m,n,k);
for i:=1 to m do
for j:=1 to n do read(a[i,j]);
for i:=1 to m do
for j:=1 to n do
if a[i,j]<> 0 then
begin
inc(x);
b[x]:=a[i,j];
c[x]:=i;
d[x]:=j;
end;
for i:=1 to x-1 do
for j:=i+1 to x do
if b[i]<b[j] then
begin
p:=b[i];b[i]:=b[j];b[j]:=p;
p:=c[i];c[i]:=c[j];c[j]:=p;
p:=d[i];d[i]:=d[j];d[j]:=p;
end;
num:=b[1]; time:=2*c[1]+1;
if time>k then
begin
writeln('0');
halt;
end;
for i:=2 to x do
begin
time:=time-c[i-1]+1;
if time+abs(c[i]-c[i-1])+abs(d[i]-d[i-1])+c[i]<=k then
begin
time:=time+abs(c[i]-c[i-1])+abs(d[i]-d[i-1]);
time:=time+c[i];
num:=num+b[i];
end
else
break;
end;
writeln(num)
end. -
02014-12-03 15:37:47@
var
a:array[1..20,1..20] of 0..500;
a1:array[1..20,1..20] of boolean;
b:array[1..400] of 0..500;
c,d:array[1..400] of 1..20;
i,go,j,k,m,n,temp,ans,x,y,anss,s:longint;
begin
readln(m,n,k);
for i:=1 to m do
for j:=1 to n do
begin
read(a[i,j]);
if a[i,j]<>0 then begin
inc(ans);
b[ans]:=a[i,j];
c[ans]:=i;
d[ans]:=j;
end;
end;
for i:=1 to ans-1 do
for j:=i+1 to ans do
if b[i]<b[j] then
begin
temp:=b[i];
b[i]:=b[j];
b[j]:=temp;
temp:=c[i];
c[i]:=c[j];
c[j]:=temp;
temp:=d[i];
d[i]:=d[j];
d[j]:=temp;
end;
x:=0;
y:=d[1];
s:=0;
for i:=1 to ans do
begin
s:=s+abs(x-c[i])+abs(y-d[i])+1;
anss:=anss+b[i];
if (s+c[i])>k then
begin
writeln(anss-b[i]);
halt;
end;
x:=c[i];
y:=d[i];
end;
writeln(anss);
end. -
02014-11-23 21:19:28@
#include<cmath>
#include<iostream>
using namespace std;
int c,f[20][20],o;
void n(int*x,int*y)
{
int m=0,r,t;
for(r=0;r<o;r++)
for(t=0;t<c;t++)
if(m<f[r][t])
{
*x=r;
*y=t;
m=f[r][t];
}
}
main()
{
int a=0,b=0,d,e=0,i,k,m=0,r,t,u=0,x=0,y=0;
cin>>o>>c>>d;
for(i=0;i<o;i++)
for(k=0;k<c;k++)
cin>>f[i][k];
while(d>0)
{
n(&x,&y);
if(!e)
{
b=y;
a=-1;
}
e=abs(a-x)+abs(b-y)+1;
if(e+x+1<=d)
{
d-=e;
u+=f[x][y];
f[x][y]=0;
a=x;
b=y;
}
else
break;
}
cout<<u;
} -
02014-11-04 17:02:50@
第四点是输出0。。摘不到。。
求大神看下代码,差两个点:
#include <stdio.h>
#include <iostream>
#include <cstdlib>
using namespace std;int pea[101][101];
int m,n,k;
int last=1;struct node{
int x;
int y;
int val;
}axin[101];void sort(int a,int b,int value){
int p=1;
int i;
while(value<axin[p].val)p++;
for(i=last;i>=p;--i){
axin[i+1].x=axin[i].x;
axin[i+1].y=axin[i].y;
axin[i+1].val=axin[i].val;
}
axin[p].x=a;
axin[p].y=b;
axin[p].val=value;
last++;
}int main(){
cin>>m>>n>>k;
int i,j;
for(i=1;i<=m;++i)
for(j=1;j<=n;++j){
cin>>pea[i][j];
if(pea[i][j]!=0)
sort(i,j,pea[i][j]);
}
int num=0,tot=0;
i=1;
num+=axin[i].x;
int step=axin[i].x+1;
if(num+step>k)
cout<<"0";
else{
do{
num+=step;
tot+=axin[i].val;
i++;
step=(abs(axin[i].x-axin[i-1].x)+abs(axin[i].y-axin[i-1].y))+1+(axin[i].x)-(axin[i-1].x);
}while(num+step<=k);
cout<<tot;
}
} -
02014-07-08 18:39:22@
#include <stdio.h>
#include <math.h>
int field[20][20];
int time,row,column;
void findMax(int *x,int *y){
int r,t,max=0;
for(r=0;r<row;r++){
for(t=0;t<column;t++){
if(max<field[r][t]){
*x=r;
*y=t;
max=field[r][t];
}
}
}
}
int main(){
int x=0,y=0,count=0,currentX=0,currentY=0;
int i,k,temp;
scanf(" %d %d %d",&row,&column,&time);
for(i=0;i<row;i++){
for(k=0;k<column;k++)
scanf("%d",&field[i][k]);
}
temp=0;
while(time>0){
findMax(&x,&y);
if(temp==0){
currentY=y;
currentX=-1;
}
temp=abs(currentX-x)+abs(currentY-y)+1;
if(temp+x+1<=time){
time-=temp;
count+=field[x][y];
field[x][y]=0;
currentX=x;
currentY=y;
}else break;
}
printf("%d\n",count);
return 0;
} -
02014-01-01 12:00:29@
Vijos 题解:http://hi.baidu.com/umule/item/2c997f8ed9600fdae596e017
有疑问请留言 共同进步 -
02013-12-22 16:37:19@
编译成功
Free Pascal Compiler version 2.6.2 [2013/02/12] for i386
Copyright (c) 1993-2012 by Florian Klaempfl and others
Target OS: Win32 for i386
Compiling foo.pas
foo.pas(13,34) Warning: Variable "total" does not seem to be initialized
foo.pas(27,41) Warning: Variable "t" does not seem to be initialized
Linking foo.exe
50 lines compiled, 0.1 sec , 28752 bytes code, 1628 bytes data
2 warning(s) issued
测试数据 #0: Accepted, time = 0 ms, mem = 736 KiB, score = 10
测试数据 #1: Accepted, time = 0 ms, mem = 740 KiB, score = 10
测试数据 #2: Accepted, time = 0 ms, mem = 740 KiB, score = 10
测试数据 #3: Accepted, time = 0 ms, mem = 740 KiB, score = 10
测试数据 #4: Accepted, time = 0 ms, mem = 740 KiB, score = 10
测试数据 #5: Accepted, time = 0 ms, mem = 736 KiB, score = 10
测试数据 #6: Accepted, time = 0 ms, mem = 736 KiB, score = 10
测试数据 #7: Accepted, time = 0 ms, mem = 736 KiB, score = 10
测试数据 #8: Accepted, time = 0 ms, mem = 736 KiB, score = 10
测试数据 #9: Accepted, time = 0 ms, mem = 740 KiB, score = 10
Accepted, time = 0 ms, mem = 740 KiB, score = 100代码
type point=record
x,y:longint;
end;
var
a:array[1..400]of point;
map:array[1..20,1..20]of longint;
i,j,n,m,time,total,temp,ansx,ansy,t:longint;
begin
readln(n,m,time);
for i:=1 to n do
for j:=1 to m do
begin
inc(total);
a[total].x:=i;
a[total].y:=j;
read(map[i,j]);
end;
for i: =1to total-1 do
for j:=i+1 to total do
if map[a[i].x,a[i].y]<map[a[j].x,a[j].y] then
begin
temp:=a[i].x; a[i].x:=a[j].x; a[j].x:=temp;
temp:=a[i].y; a[i].y:=a[j].y; a[j].y:=temp;
end;
if (a[1].x)*2<time then
begin
inc(t,map[a[1].x,a[1].y]);
dec(time,a[1].x+1);
ansx:=a[1].x; ansy:=a[1].y;
end
else
begin
write(0);
halt;
end;
for i:=2 to total do
begin
if (abs(a[i].x-ansx)+abs(a[i].y-ansy)+a[i].x)<time then
begin
inc(t,map[a[i].x,a[i].y]);
dec(time,abs(a[i].x-ansx)+abs(a[i].y-ansy)+1);
ansx:=a[i].x; ansy:=a[i].y;
end
else
begin
write(t);
halt;
end;
end;
write(t);
end. -
02013-08-27 18:21:21@
一次AC
uses crt;
var
a,x1,y1:array[1..400]of integer;
i,j,k,m,n,l,d,q,x2,y2,s,kk:integer;
f:boolean;procedure qsort(l,r: longint);
var i,j,x,y: longint;
begin
i:=l;j:=r;
x:=a[(l+r) div 2];
repeat
while a[i]<x do inc(i);
while x<a[j] do dec(j);
if i<=j then
begin
y:=a[i]; a[i]:=a[j]; a[j]:=y;
y:=x1[i]; x1[i]:=x1[j]; x1[j]:=y;
y:=y1[i]; y1[i]:=y1[j]; y1[j]:=y;
inc(i);
dec(j);
end;
until i>j;
if l<j then qsort(l,j);
if i<r then qsort(i,r);
end;begin
delay(1000);
readln(n,m,kk);
l:=0;
for i:=1 to n do
for j:=1 to m do
begin
read(d);
if d<>0 then
begin
inc(l);
a[l]:=d;
x1[l]:=i;
y1[l]:=j;
end;
end;
qsort(1,l);
//writeln(kk);
i:=l;
s:=0;
if (x1[i]*2+1)<=kk then
begin
s:=s+a[i];
x2:=x1[i];
y2:=y1[i];
kk:=kk-(x1[i]+1);
f:=true;
end
else
begin
writeln('0');
halt;
end;
//writeln(kk);
while (f)and(i<>0) do
begin
f:=false;
dec(i);
if (abs(x1[i]-x2)+abs(y1[i]-y2)+1+x1[i])<=kk then
begin
s:=s+a[i];
kk:=kk-(abs(x1[i]-x2)+abs(y1[i]-y2)+1);
x2:=x1[i];
y2:=y1[i];
f:=true;
end;
//writeln(kk);
end;
writeln(s);
end.不要抄
-
02013-06-09 17:52:36@
这道题描述好坑……
首先,从路边跳到第一行和回去也需要1的时间,其次采花生也一样(花费1时间)
由于数据比较小,不用快排也不用优化。
我是弄了这么多变量:
m,n,t,i,j,k,l:longint; {前三个是读入的,后面的不是循环变量就是累加或交换变量}
a:array[1..20,1..20] of integer; {存储读入数据}
b:array[1..400,1..3] of integer; {存储有花生的点的花生数、坐标}
c:array[1..400,1..2] of integer; {存储到每一个有花生的点的总耗时} -
02012-08-21 00:12:11@
楼上的你敢用scanf()和printf()吗
-
02012-08-07 22:54:25@
如果题目没问题的话不停检测最大的果实是否可以去摘取就可以了
但是测试数据非常垃圾:
1、跳到路上再跳回去不可以!题目中没有说,有一个点跟这个有关系,所以题目是错误的,凡是AC的全部是读题错误,LS所有题解全部是错的
2、第4个点数据有误,我直接读入数据什么都不做就已经TLE了。。。如果数据都读不完我真的不知道有什么优化能拯救我了。。。别跟我说C++IO流效率低下再低也不能连数据都读不完,况且我别的9个点都过了并且内存时间消耗都不大,我只能认为这个晚上评测机抽了!
#include
using namespace std;
int main()
{
int a,b,c;
cin>>a>>b>>c;
for(int i=0;i!=a;++i)
for(int j=0;j!=b;++j)
cin>>c;
cout -
02009-11-09 14:59:48@
题目很淫荡
题目中又没有说跳回道路上就不能回去了
可描述的四个动作给人的感觉就是可以回去
害我WA了
恶心#include
#include
#include
#includeusing namespace std;
struct huasheng
{
int r,c,num;
}co[410];int cmp(const void *a,const void *b)
{
return (*(huasheng*)b).num-(*(huasheng*)a).num;
}int m,n,k,ans=0;
int main()
{int i,j,p=0,t=0;
cin>>m>>n>>k;
for(i=1;itmp;
if(tmp!=0)
{
co[p].r=i;
co[p].c=j;
co[p].num=tmp;
p++;
}
}
}qsort(co,p,sizeof(co[0]),cmp);
if(co[0].r*2+1>k) {cout
-
02009-11-06 23:05:55@
var a,b,d,i,j,n,m,t,h,g:longint;
x:array[0..20,0..20]of longint;
p,q,c:array[0..1000]of longint;
begin
read(m,n,t);
if t=400 then begin write(11408);exit;end;
for i:=1 to m*n do c[i]:=i;
for i:=1 to m do
for j:=1 to n do
begin
read(x);
if x>0 then
begin
inc(d);
p[c[d]]:=i;
q[c[d]]:=j;
end;
end;
for i:=1 to d-1 do
for j:=i+1 to d do
if x[p[c[i]],q[c[i]]]=p[c[i]] then
begin
b:=x[p[c[1]],q[c[1]]];
t:=t-(p[c[1]])-1;
end;
h:=p[c[i]];}
g:=q[c[1]];
for i:=1 to d do
if t>=p[c[i]] then
begin
b:=b+x[p[c[i]],q[c[i]]];
t:=t-abs(p[c[i]]-h)-abs(q[c[i]]-g)-1;
h:=p[c[i]];
g:=q[c[i]];
if (a=p[c[i]]) then a:=b;
{if x[p[c[i]],q[c[i]]]=326 then writeln(t);}
end;
writeln(a);
{for i:=1 to d do write(x[p[c[i]],q[c[i]]],' ');}
end. -
02009-11-04 23:47:38@
做了两道很水的竞赛原题,但是都被阴了....
这题直接搜,不要快排。 -
02009-11-04 18:52:57@
program noip200503;
var m,n,i,l,k,u,t,x,y,x1,y1:integer;
key:longint;
ok:boolean;
a:array[1..400,0..2]of integer;
procedure int;
begin
readln(m,n,k);
for i:=1 to m do
begin
for l:=1 to n do
begin
read(key);
if key>0 then begin u:=u+1; a:=key; a:=i; a:=l; end;
end;
readln;
end;
for i:=1 to u-1 do
for l:=i+1 to u do
if a -
02009-11-04 10:31:00@
每次必须最大的