50 条题解
-
087443555seer LV 8 @ 2014-10-28 18:39:11
var
i,j,n,m,s:longint;
a:array[1..1000000] of 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(n);
for i:=1 to n do
readln(a[i]);
sort(1,n);
s:=1;
for i:=1 to n do
begin
if a[i+1]=a[i] then inc(s)
else
begin
writeln(a[i],' ',s);
s:=1;
end;
end;
end. -
02014-09-22 20:11:01@
std::map
##code
#include <iostream>
#include <map>
#include <cstdio>
using namespace std;
map<int,int> t;
int n=0;
int main()
{
cin>>n;
for(int i=0;i!=n;++i)
{
int temp=0;
scanf("%d",&temp);
if(t.count(temp)) t[temp]++;
else t.insert(pair<int,int>(temp,1));
}
for(map<int,int>::iterator i=t.begin();i!=t.end();++i)
printf("%d %d\n",i->first,i->second);
return 0;
} -
02014-07-17 12:37:05@
#include <stdio.h>
long arr[300000];
long temp=0;
void quickSort(int left,int right){
int l=left,r=right;
int mid=arr[(left+right)/2];
while(l<=r){
while(arr[l]<mid)
l++;
while(arr[r]>mid)
r--;
if(l<=r){
temp=arr[l];
arr[l]=arr[r];
arr[r]=temp;
l++;
r--;
}
}
if(left<r)
quickSort(left,r);
if(l<right)
quickSort(l,right);
}
int main(){
int totalNum,count=0;
int i;
scanf("%d",&totalNum);
for(i=0;i<totalNum;i++)
scanf("%ld",&arr[i]);
quickSort(0,totalNum-1);
temp=arr[0];
for(i=0;i<totalNum;i++){
if(temp==arr[i]){
count++;
}else{
printf("%ld %d\n",temp,count);
count=1;
temp=arr[i];
}
}
printf("%ld %d\n",temp,count);
return 0;
} -
02014-01-28 17:04:17@
排序,然后一切都好办,排序当然是qsort了。
排序,然后一切都好办,排序当然是qsort了。
排序,然后一切都好办,排序当然是qsort了。 -
02014-01-01 12:02:58@
Vijos 题解:http://hi.baidu.com/umule/item/2c997f8ed9600fdae596e017
有疑问请留言 共同进步 -
02013-11-05 08:16:44@
var
i,j,n,m,s:longint;
a:array[1..1000000] of 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(n);
for i:=1 to n do
readln(a[i]);
sort(1,n);
s:=1;
for i:=1 to n do
begin
if a[i+1]=a[i] then inc(s)
else
begin
writeln(a[i],' ',s);
s:=1;
end;
end;
end.
快排即可。 -
02013-10-23 09:01:53@
评测结果
编译成功测试数据 #0: Accepted, time = 0 ms, mem = 1324 KiB, score = 10
测试数据 #1: Accepted, time = 0 ms, mem = 1320 KiB, score = 10
测试数据 #2: Accepted, time = 15 ms, mem = 1320 KiB, score = 10
测试数据 #3: Accepted, time = 15 ms, mem = 1320 KiB, score = 10
测试数据 #4: Accepted, time = 31 ms, mem = 1320 KiB, score = 10
测试数据 #5: Accepted, time = 31 ms, mem = 1320 KiB, score = 10
测试数据 #6: Accepted, time = 31 ms, mem = 1316 KiB, score = 10
测试数据 #7: Accepted, time = 93 ms, mem = 1320 KiB, score = 10
测试数据 #8: Accepted, time = 62 ms, mem = 1316 KiB, score = 10
测试数据 #9: Accepted, time = 0 ms, mem = 1320 KiB, score = 10
Accepted, time = 278 ms, mem = 1324 KiB, score = 100
代码
#include<cstdio>
#include<algorithm>
int n,t=1,a[200100];
int main(){
scanf("%d",&n);
for (int i=1; i<n+1; i++) scanf("%d",&a[i]);
std::sort(a+1,a+n+1);
for (int i=2; i<n+2; i++)
if (a[i]==a[i-1]) t++;
else { printf("%d %d\n",a[i-1],t); t=1;}
} -
02013-08-31 14:24:11@
脑残的我10分钟顺手抽了一道SBT。。。。还挺快的 建树后前序遍历输出就好啦~~~
编译成功测试数据 #0: Accepted, time = 15 ms, mem = 4648 KiB, score = 10
测试数据 #1: Accepted, time = 0 ms, mem = 4652 KiB, score = 10
测试数据 #2: Accepted, time = 0 ms, mem = 4652 KiB, score = 10
测试数据 #3: Accepted, time = 0 ms, mem = 4648 KiB, score = 10
测试数据 #4: Accepted, time = 46 ms, mem = 4648 KiB, score = 10
测试数据 #5: Accepted, time = 78 ms, mem = 4648 KiB, score = 10
测试数据 #6: Accepted, time = 31 ms, mem = 4648 KiB, score = 10
测试数据 #7: Accepted, time = 93 ms, mem = 4648 KiB, score = 10
测试数据 #8: Accepted, time = 78 ms, mem = 4648 KiB, score = 10
测试数据 #9: Accepted, time = 15 ms, mem = 4652 KiB, score = 10
Accepted, time = 356 ms, mem = 4652 KiB, score = 100
const maxn = 200000;
var
k,s,l,r,w:array[0..200000] of longint;
n,m:longint;
roof:longint;
procedure left_ratote(var t:longint);
var k:longint;
begin
k:=r[t];
r[t]:=l[k];
s[t]:=s[l[t]]+s[r[t]]+1;
l[k]:=t;
s[k]:=s[l[k]]+s[r[k]]+1;
t:=k;
end;
procedure right_ratote(var t:longint);
var k:longint;
begin
k:=l[t];
l[t]:=r[k];
s[t]:=s[l[t]]+s[r[t]]+1;
r[k]:=t;
s[k]:=s[l[k]]+s[r[k]]+1;
t:=k;
end;
procedure maintain(var t:longint);
begin
if s[l[l[t]]]>s[r[t]] then
begin
right_ratote(l[t]);
maintain(r[t]);
maintain(t);
exit;
end;
if s[r[l[t]]]>s[r[t]] then
begin
left_ratote(l[t]);
right_ratote(t);
maintain(l[t]);
maintain(r[t]);
maintain(t);
exit;
end;
if s[r[r[t]]]>s[l[t]] then
begin
left_ratote(t);
maintain(l[t]);
maintain(t);
exit;
end;
if s[l[r[t]]]>s[l[t]] then
begin
right_ratote(r[t]);
left_ratote(t);
maintain(l[t]);
maintain(r[t]);
maintain(t);
exit;
end;
end;
function insert(key:longint;var t:longint):boolean;
var flag:boolean;
begin
if t=0 then
begin
inc(m);
t:=m;
k[t]:=key;
s[t]:=1;
w[t]:=1;
exit(true);
end;
if k[t]=key then
begin
inc(w[t]);
exit(false);
end;
if key<k[t] then flag:=insert(key,l[t])
else flag:=insert(key,r[t]);
if flag then
begin
inc(s[t]);
maintain(t);
end;
end;
procedure init;
var i,x:longint;
begin
fillchar(l,sizeof(l),0);
fillchar(r,sizeof(r),0);
fillchar(s,sizeof(s),0);
m:=0;
roof:=0;
readln(n);
for i:=1 to n do
begin
read(x);
insert(x,roof);
end;
end;
procedure output(t:longint);
begin
if l[t]>0 then output(l[t]);
writeln(k[t],' ',w[t]);
if r[t]>0 then output(r[t]);
end;
begin
init;
output(roof);
end. -
02013-08-23 10:44:48@
就普通的快排就行了...
var
a,b,c:array[1..200000] of longint;
i,j,k,n,m,tot: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(n);
for i:=1 to n do readln(a[i]);
sort(1,n); k:=0; j:=0;
for i:=1 to n do
begin
if a[i]=k then inc(j)
else
begin
inc(tot);
b[tot]:=k;
c[tot]:=j;
k:=a[i];
j:=1;
end;
end;
for i:=2 to tot do
writeln(b[i],' ',c[i]);
writeln(k,' ',j);
end. -
-12016-11-17 17:37:52@
恕我直言 在座的都是傻逼
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int s[500000];
int main(){
int n;
cin>>n;
for(int i=1;i<=n;i++)
scanf("%d",&s[i]);
sort(s+1,s+n+1);
int ans=1;
for(int i=2;i<=n;i++){
if(s[i-1]==s[i]){
ans++;
continue;
}
cout<<s[i-1]<<" "<<ans<<endl;
ans=1;
}
cout<<s[n]<<" "<<ans<<endl;
return 0;
}
信息
- ID
- 1816
- 难度
- 4
- 分类
- (无)
- 标签
- 递交数
- 2916
- 已通过
- 1143
- 通过率
- 39%
- 被复制
- 7
- 上传者