229 条题解
-
-1SZZXxnw LV 7 @ 2016-09-13 18:42:17
#include<bits/stdc++.h>
using namespace std;
bool use[30000];
int main(){
int w,n,ans=0;
cin>>w>>n;
int a[n];
for(int i=0;i<n;i++){
scanf("%d",&a[i]);
}
sort(a,a+n);
for(int i=0;i<n;i++){
if(!use[i]){
use[i]=true;
for(int j=n-1;j>0;j--){
if(!use[j]&&w-a[j]-a[i]>=0){
use[j]=true;
break;
}
}
ans++;
}
}
cout<<ans;
}
蒙的一逼 -
-12016-08-18 19:17:43@
pascal
var
w,i,j,ans,k,n:longint;
p:array[1..30000] of integer;
begin
readln(w);
readln(n);
for i:=1 to n do readln(p[i]);for i:=1 to n-1 do
for j:=i+1 to n do if p[i]<p[j] then begin
k:=p[i];p[i]:=p[j];p[j]:=k;
end;ans:=0;i:=1;j:=n;
while n>0 do begin
inc(ans);
if (p[i]+p[j]>w) then begin inc(i);dec(n);end
else begin inc(i);dec(n,2);dec(j);end;
end;writeln(ans);
end. -
-12016-08-15 14:29:14@
C++,写的有点烦:
#include <iostream>
using namespace std;void run(int*pData,int left,int right)
{
int i,j;
int middle,iTemp;
i=left;
j=right;
middle=pData[(left+right)/2];//求中间值
do
{
while((pData[i]<middle)&&(i<right))//从左扫描大于中值的数
i++;
while((pData[j]>middle)&&(j>left))//从右扫描大于中值的数
j--;
if(i<=j)//找到了一对值
{
//交换
iTemp=pData[i];
pData[i]=pData[j];
pData[j]=iTemp;
i++;
j--;
}
}while(i<=j);//如果两边扫描的下标交错,就停止(完成一次)//当左边部分有值(left<j),递归左半边
if(left<j)
run(pData,left,j);
//当右边部分有值(right>i),递归右半边
if(right>i)
run(pData,i,right);
}
void QuickSort(int*pData,int Count)
{
run(pData,0,Count-1);
}int main()
{
int w,n,p[30000],t=0;
int ans=0;
cin>>w>>n;
for(int i=0;i<n;i++)cin>>p[i];
QuickSort(p,n);
int k=0;
for(int j=n-1;;j--)
{
t++;
while(p[j]<w&&(p[j]+p[k]<=w))
{
t++;
if(t>=n)break;
p[j]+=p[k];
k++;
}
ans++;
if(t>=n)break;
}cout<<ans<<endl;
} -
-12016-08-14 22:04:13@
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
using namespace std;
int a[30010] = {};
int main()
{
int w, n ,ans = 0;
scanf("%d%d", &w, &n);
for(int i = 1;i <= n; i++)
scanf("%d", &a[i]);
sort(a+1, a+1+n);
int i=1,j=n;
while(i<=j){
if(a[i]+a[j]<=w&&i<j)
i++;
j--;
ans++;
}
printf("%d\n", ans);
return 0;
} -
-12016-08-10 14:21:35@
var a:array[1..30000]of longint;
i,j,k,ans,w,n,t,x:longint;procedure sort(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 not(i>j) then
begin
y:=a[i];
a[i]:=a[j];
a[j]:=y;
inc(i);
j:=j-1;
end;
until i>j;
if l<j then
sort(l,j);
if i<r then
sort(i,r);
end;begin
readln(w,n);
ans:=0;x:=0;
for i:=1 to n do readln(a[i]);
sort(1,n);
i:=1;j:=n;
while i<j do
begin
if a[i]+a[j]<=w then
begin
i:=i+1;
j:=j-1;
inc(ans);
end
else begin j:=j-1;inc(ans);x:=x+1;end;
end;
if (n-x) mod 2 =1 then inc(ans);
writeln(ans);
end. -
-12016-06-22 13:32:03@
水题
-
-12013-04-16 23:38:42@
var n,m,t,i,j,s:integer;
a:array[1..100000]of integer;
begin
readln(n); readln(m);
for i:= 1 to m do
readln(a[i]);
for i:=1 to m-1 do
begin
for j:=i+1 to m do
begin
if a[i]<a[j] then
begin
s:=a[i]; a[i]:=a[j]; a[j]:=s;
end;
end;
end;
i:=1;
t:=n;
s:=0;
repeat
if i<>m then
begin
if a[i]+a[m]<=t then
begin
i:=i+1;
m:=m-1;
s:=s+1;
end else
begin
i:=i+1;
s:=s+1;
end;
if i=m then
begin
s:=s+1;
m:=m-1;
end;
end;
until i>m;
writeln(s);
readln;
readln
end. -
-22016-07-14 20:27:09@
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> using namespace std; long long w,n,a[300001],cou,ans,tor; int main() { ios::sync_with_stdio(false); cin>>w>>n; for(int i=1;i<=n;i++) cin>>a[i]; sort(a+1,a+n+1); tor=n; long long head=1,tail=n; while(head<=tail) { if(a[head]+a[tail]<=w) { ans++; head++; tail--; } else { tail--; ans++; } } cout<<ans<<endl; return 0; }
题题题题题题题题题题题题题题题题题题题题题题题题题题题题题题题题题题题题题
题题题题题题题题题题题题题题题题题题题题题题题题题题题题水水水水题题题题题
题题题题题题题题题题题题题题题题题题题题题题题题水水水水水水水水水题题题题
题题题题题题题题题题题题题题题题题题水水水水水水水水水水水水水水水题题题题
题题题题题题题题题题题题题题题题水水水水水水水水水水水水水水水题题题题题题
题题题题题题题题题题题水水水水题水水水水水水水水水水水题题题题题题题题题题
题题题题题题题题水水水水水水水题水水水题题水水水水水题题题题题题题题题题题
题题题水水水水水水水水水水水水题题题题题题水水水水题题题题题题题题题题题题
题水水水水水水水水水水水水水水题题题题题题水水水水题题题题题题题题题题题题
题水水水水水水水水水水水水题题题题题题题水水水水水水水水水水水题题题题题题
题水水水水水水水水水水水水题题题题题题水水水水水水水水水水水水水水题题题题
题题水水水水水水水水水水题题题题题水水水水水水题题题水水水水水水水题题题题
题题题题题题题题水水水水题题题题题水水水水题题题题题题水水水水水题题题题题
题题题题题题题题水水水水题题题题水水水水题题水水题题题水水水水水题题题题题
题题题题题题题题水水水水题题题题水水水水题题水水水水题水水水水水题题题题题
题题题题题题题题水水水水题题题题水水水水题题水水水水题水水水水水题题题题题
题题题题题题题题水水水水题题题题水水水水题题水水水题题水水水水水题题题题题
题题题题题题题题水水水水题题题题水水水水题题水水水题题水水水水水题题题题题
题题题题题题题题水水水水题题题题水水水水题水水水水题题水水水水水题题题题题
题题题题题题题题水水水水题题题题水水水水题水水水水题题水水水水水题题题题题
题题题题题题题题水水水水题题题题水水水水题水水水水题题水水水水水题题题题题
题题题题题题题题水水水水题题题题水水水水题水水水水题题水水水水水题题题题题
题题题题题题题题水水水水题题题题水水水题题水水水水题题水水水水水题题题题题
题题水水题题题水水水水水题题题题水水水题题水水水题题题水水水水水题题题题题
题题水水水水水水水水水水题题题题题水水题题水水题题题题水水水水水题题题题题
题题题水水水水水水水水水题题题题题题题题水水水题题题题水水水水题题题题题题
题题题题题水水水水水水水题题题题题题题题水水水题水水水水题题题题题题题题题
题题题题题题水水水水水水题题题题题题题水水水水题题水水水水题题题题题题题题
题题题题题题题题题水水水题题题题题题水水水水水题题题水水水水水水水题题题题
题题题题题题题题题题题题题题题题水水水水水水题题题题题水水水水水水题题题题
题题题题题题题题题题题题题题题水水水水水水题题题题题题水水水水水水水题题题
题题题题题题题题题题题题题题水水水水水题题题题题题题题题水水水水水水题题题
题题题题题题题题题题题题题水水水水水题题题题题题题题题题题水水水水题题题题
题题题题题题题题题题题题水水水题题题题题题题题题题题题题题题水水水题题题题
题题题题题题题题题题题题题题题题题题题题题题题题题题题题题题题题题题题题题 -
-32016-05-21 17:02:32@
题题题题题题题题题题题题题题题题题题题题题题题题题题题题题题题题题题题题题
题题题题题题题题题题题题题题题题题题题题题题题题题题题题水水水水题题题题题
题题题题题题题题题题题题题题题题题题题题题题题题水水水水水水水水水题题题题
题题题题题题题题题题题题题题题题题题水水水水水水水水水水水水水水水题题题题
题题题题题题题题题题题题题题题题水水水水水水水水水水水水水水水题题题题题题
题题题题题题题题题题题水水水水题水水水水水水水水水水水题题题题题题题题题题
题题题题题题题题水水水水水水水题水水水题题水水水水水题题题题题题题题题题题
题题题水水水水水水水水水水水水题题题题题题水水水水题题题题题题题题题题题题
题水水水水水水水水水水水水水水题题题题题题水水水水题题题题题题题题题题题题
题水水水水水水水水水水水水题题题题题题题水水水水水水水水水水水题题题题题题
题水水水水水水水水水水水水题题题题题题水水水水水水水水水水水水水水题题题题
题题水水水水水水水水水水题题题题题水水水水水水题题题水水水水水水水题题题题
题题题题题题题题水水水水题题题题题水水水水题题题题题题水水水水水题题题题题
题题题题题题题题水水水水题题题题水水水水题题水水题题题水水水水水题题题题题
题题题题题题题题水水水水题题题题水水水水题题水水水水题水水水水水题题题题题
题题题题题题题题水水水水题题题题水水水水题题水水水水题水水水水水题题题题题
题题题题题题题题水水水水题题题题水水水水题题水水水题题水水水水水题题题题题
题题题题题题题题水水水水题题题题水水水水题题水水水题题水水水水水题题题题题
题题题题题题题题水水水水题题题题水水水水题水水水水题题水水水水水题题题题题
题题题题题题题题水水水水题题题题水水水水题水水水水题题水水水水水题题题题题
题题题题题题题题水水水水题题题题水水水水题水水水水题题水水水水水题题题题题
题题题题题题题题水水水水题题题题水水水水题水水水水题题水水水水水题题题题题
题题题题题题题题水水水水题题题题水水水题题水水水水题题水水水水水题题题题题
题题水水题题题水水水水水题题题题水水水题题水水水题题题水水水水水题题题题题
题题水水水水水水水水水水题题题题题水水题题水水题题题题水水水水水题题题题题
题题题水水水水水水水水水题题题题题题题题水水水题题题题水水水水题题题题题题
题题题题题水水水水水水水题题题题题题题题水水水题水水水水题题题题题题题题题
题题题题题题水水水水水水题题题题题题题水水水水题题水水水水题题题题题题题题
题题题题题题题题题水水水题题题题题题水水水水水题题题水水水水水水水题题题题
题题题题题题题题题题题题题题题题水水水水水水题题题题题水水水水水水题题题题
题题题题题题题题题题题题题题题水水水水水水题题题题题题水水水水水水水题题题
题题题题题题题题题题题题题题水水水水水题题题题题题题题题水水水水水水题题题
题题题题题题题题题题题题题水水水水水题题题题题题题题题题题水水水水题题题题
题题题题题题题题题题题题水水水题题题题题题题题题题题题题题题水水水题题题题
题题题题题题题题题题题题题题题题题题题题题题题题题题题题题题题题题题题题题