# HDOJ水题集合11：桶排序, 折半搜索

Solved Problem ID Title Ratio(Accepted / Submitted)
1001 sort 31.25%(15/48)
1002 解方程 34.29%(12/35)

#### 1001 sort

Time Limit : 6000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 48 Accepted Submission(s) : 15
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description

Input

Output

Sample Input
5 3
3 -35 92 213 -644
Sample Output
213 92 3
Hint

Author
LL
Source
ACM暑期集训队练习赛（三）

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 5e5+10;
int a[maxn*2];
int main(){
ios::sync_with_stdio(false);
int n, m;
while(cin>>n>>m){
memset(a,0,sizeof(a));
for(int i = 1; i <= n; i++){
int x; cin>>x; a[x+maxn]++;
}
int bk = 0;
for(int i = maxn*2-1; i >= 0; i--){
while(a[i] && m){
if(bk)cout<<" ";
cout<<i-maxn;
a[i]--; m--;
bk = 1;
}
if(m==0)break;
}
cout<<"\n";
}
return 0;
}



#### 1002 解方程

Time Limit : 6000/3000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 35 Accepted Submission(s) : 12
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description

ax12 + bx22 + cx32 + dx42=0

a, b, c, d在整数区间[-50,50]内取值，并且都不等于0.

Input

Output

Sample Input
1 2 3 -4
1 1 1 1
Sample Output
39088
0

//变形得a*x1^2+b*x2^2=-c*x3^2-d*x4^2
//从1-100枚举x1,x2，记录解的值，再枚举x3,x4判断是否存在，有就累加
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 2e6+10, P=maxn/2;//+P防止负数
int h[maxn], f[110];
int main(){
for(int i = 1; i <= 100; i++)f[i]=i*i;
int a, b, c, d;
while(scanf("%d%d%d%d",&a,&b,&c,&d)!=EOF){
if(a<0&&b<0&&c<0&&d<0||a>0&&b>0&&c>0&&d>0){
printf("0\n"); continue;
}
int ans = 0;
for(int i = 1; i <= 100; i++)
for(int j = 1; j <= 100; j++)
h[a*f[i]+b*f[j]+P]++;
for(int i = 1; i <= 100; i++)
for(int j = 1; j <= 100; j++)
ans += h[-c*f[i]-d*f[j]+P];
printf("%d\n", 16*ans);//2^4种交换abcd组合
memset(h,0,sizeof(h));
}
return 0;
}