Merge pull request #12 from KiritoTRw/master

A few problems solved.
This commit is contained in:
Kirigaya Kazuto 2016-05-02 14:08:10 +08:00
commit 048745e657
9 changed files with 283 additions and 0 deletions

43
QUSTOJ/1092.cpp Normal file
View File

@ -0,0 +1,43 @@
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
#define MAXN 50005
struct pack
{
long a,b,c;
};
pack PK[MAXN];
int W[16];
bool cmp(pack a,pack b){
return (a.a>b.a) || (a.a==b.a && a.c<b.c);
}
int main()
{
int n,k;
scanf("%d %d",&n,&k);
for(int i=0;i<10;i++)
{
scanf("%d",&W[i]);
}
for(int i=0;i<n;i++)
{
scanf("%ld",&PK[i].a);
PK[i].c=i+1;
}
sort(PK,PK+n,cmp);
for (int i=0;i<n;i++){
PK[i].b=i;
PK[i].a+=W[PK[i].b%10];
}
sort(PK,PK+n,cmp);
for (int i=0;i<k;i++){
printf("%ld",PK[i].c);
if (i+1==k) printf("\n");
else printf(" ");
}
return 0;
}

37
QUSTOJ/1092.pas Normal file
View File

@ -0,0 +1,37 @@
var e:array[1..10] of longint;
w,d:array[1..50000] of longint;
i,m,n,j:longint;
procedure ss(x,y:longint);
var ii,jj,s,o,aa:longint;
begin
ii:=x;jj:=y;
s:=w[(x+y) shr 1];
aa:=d[(x+y) shr 1];
repeat
while (w[ii]>s) or ((w[ii]=s) and (d[ii]<aa)) do inc(ii);
while (w[jj]<s) or ((w[jj]=s) and (d[jj]>aa)) do dec(jj);
if ii<=jj then begin
o:=w[ii];w[ii]:=w[jj];w[jj]:=o;
o:=d[ii];d[ii]:=d[jj];d[jj]:=o;
inc(ii);dec(jj);
end;
until ii>jj;
if x<jj then ss(x,jj);
if ii<y then ss(ii,y);
end;
begin
readln(n,m);
for i:=1 to 10 do read(e[i]);
readln;
for i:=1 to n do read(w[i]);
for i:=1 to n do d[i]:=i;
ss(1,n);
for i:=1 to n do w[i]:=w[i]+e[(i-1) mod 10+1];
ss(1,n);
if m=0 then halt;
write(d[1]);
for i:=2 to m do write(' ',d[i]);
readln;
end.

32
QUSTOJ/1092_972964894.cpp Normal file
View File

@ -0,0 +1,32 @@
#include<iostream>
#include<algorithm>
using namespace std;
struct leaf{
long long x,y,z;
}a[50000];
long long n,k,w[10],i;
bool cmp(leaf a,leaf b){
return (a.x>b.x) || (a.x==b.x && a.z<b.z);
}
int main(){
cin>>n>>k;
for (i=0;i<10;i++) cin>>w[i];
for (i=0;i<n;i++){
cin>>a[i].x;
a[i].z=i+1;
}
sort(a,a+n,cmp);
for (i=0;i<n;i++){
a[i].y=i;
a[i].x+=w[a[i].y%10];
}
sort(a,a+n,cmp);
for (i=0;i<k;i++){
cout<<a[i].z;
if (i+1==k) cout<<endl;
else cout<<' ';
}
return 0;
}

29
QUSTOJ/1099_HBat.cpp Normal file
View File

@ -0,0 +1,29 @@
#include <iostream>
#include <stdio.h>
#include <algorithm>
using namespace std;
int n,m,a[2010],t[2010];
int main()
{
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
for(int i=1;i<=m;i++)
scanf("%d",&t[i]);
int left=m;
sort(t+1,t+m+1);
for(int i=1;i<=n;i++)
{
for(int j=m;j>0;j--)
{
if(a[i]>t[j]&&t[j]!=0)
{
t[j]=0;
left--;
break;
}
}
}
printf("%d",left);
}

22
QUSTOJ/1099_guoqianli.pas Normal file
View File

@ -0,0 +1,22 @@
var a,b:array[1..10000]of longint;
c,d:array[1..10000]of boolean;
n,m,i,j,k,max:longint;
begin
max:=0;
fillchar(c,sizeof(c),true);
d:=c;
readln(n,m);
for i:=1 to n do readln(a[i]);
for i:=1 to m do readln(b[i]);
for i:=1 to n-1 do
for j:=i+1 to n do
if a[i]<a[j] then begin k:=a[i]; a[i]:=a[j]; a[j]:=k; end; for i:=1 to m-1 do for j:=i+1 to m do if b[i]<b[j] then begin k:=b[i]; b[i]:=b[j]; b[j]:=k; end; for i:=1 to n do for j:=1 to m do if b[j]>0 then
if (a[i]>b[j])and(c[i])and(d[j])then
begin
inc(max);
c[i]:=false;
d[j]:=false;
break;
end;
writeln(m-max);
end.

37
VIJOS/1282.pas Normal file
View File

@ -0,0 +1,37 @@
var e:array[1..10] of longint;
w,d:array[1..50000] of longint;
i,m,n,j:longint;
procedure ss(x,y:longint);
var ii,jj,s,o,aa:longint;
begin
ii:=x;jj:=y;
s:=w[(x+y) shr 1];
aa:=d[(x+y) shr 1];
repeat
while (w[ii]>s) or ((w[ii]=s) and (d[ii]<aa)) do inc(ii);
while (w[jj]<s) or ((w[jj]=s) and (d[jj]>aa)) do dec(jj);
if ii<=jj then begin
o:=w[ii];w[ii]:=w[jj];w[jj]:=o;
o:=d[ii];d[ii]:=d[jj];d[jj]:=o;
inc(ii);dec(jj);
end;
until ii>jj;
if x<jj then ss(x,jj);
if ii<y then ss(ii,y);
end;
begin
readln(n,m);
for i:=1 to 10 do read(e[i]);
readln;
for i:=1 to n do read(w[i]);
for i:=1 to n do d[i]:=i;
ss(1,n);
for i:=1 to n do w[i]:=w[i]+e[(i-1) mod 10+1];
ss(1,n);
if m=0 then halt;
write(d[1]);
for i:=2 to m do write(' ',d[i]);
readln;
end.

32
VIJOS/1282_972964894.cpp Normal file
View File

@ -0,0 +1,32 @@
#include<iostream>
#include<algorithm>
using namespace std;
struct leaf{
long long x,y,z;
}a[50000];
long long n,k,w[10],i;
bool cmp(leaf a,leaf b){
return (a.x>b.x) || (a.x==b.x && a.z<b.z);
}
int main(){
cin>>n>>k;
for (i=0;i<10;i++) cin>>w[i];
for (i=0;i<n;i++){
cin>>a[i].x;
a[i].z=i+1;
}
sort(a,a+n,cmp);
for (i=0;i<n;i++){
a[i].y=i;
a[i].x+=w[a[i].y%10];
}
sort(a,a+n,cmp);
for (i=0;i<k;i++){
cout<<a[i].z;
if (i+1==k) cout<<endl;
else cout<<' ';
}
return 0;
}

29
VIJOS/1291_HBat.cpp Normal file
View File

@ -0,0 +1,29 @@
#include <iostream>
#include <stdio.h>
#include <algorithm>
using namespace std;
int n,m,a[2010],t[2010];
int main()
{
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
for(int i=1;i<=m;i++)
scanf("%d",&t[i]);
int left=m;
sort(t+1,t+m+1);
for(int i=1;i<=n;i++)
{
for(int j=m;j>0;j--)
{
if(a[i]>t[j]&&t[j]!=0)
{
t[j]=0;
left--;
break;
}
}
}
printf("%d",left);
}

22
VIJOS/1291_guoqianli.pas Normal file
View File

@ -0,0 +1,22 @@
var a,b:array[1..10000]of longint;
c,d:array[1..10000]of boolean;
n,m,i,j,k,max:longint;
begin
max:=0;
fillchar(c,sizeof(c),true);
d:=c;
readln(n,m);
for i:=1 to n do readln(a[i]);
for i:=1 to m do readln(b[i]);
for i:=1 to n-1 do
for j:=i+1 to n do
if a[i]<a[j] then begin k:=a[i]; a[i]:=a[j]; a[j]:=k; end; for i:=1 to m-1 do for j:=i+1 to m do if b[i]<b[j] then begin k:=b[i]; b[i]:=b[j]; b[j]:=k; end; for i:=1 to n do for j:=1 to m do if b[j]>0 then
if (a[i]>b[j])and(c[i])and(d[j])then
begin
inc(max);
c[i]:=false;
d[j]:=false;
break;
end;
writeln(m-max);
end.