170 条题解
-
0whilish LV 5 @ 2016-04-26 08:46:05
#include <stdio.h> #define MAX_PAIRS 2000 int main() { int n, a[2 * MAX_PAIRS + 1] = {0}, l = 0, r, i, j; scanf("%d", &n); for (i = 0; i < n; ++i) { scanf("%d", &r); for(j = 0; j < r - l; ++j) a[++a[0]] = 1; for(j = 0; a[a[0] - j] != 1; ++j) ; printf("%d ", j/2 + 1); a[a[0]++ - j] = 0; l = r; } return 0; }
-
02016-04-19 12:16:49@
var a:array[0..2000] of qword; i,n,k,tmp1,tmp2:longint; begin fillchar(a,sizeof(a),0); read(n); tmp2:=0; for i:=1 to n do begin read(tmp1); //a[i]表示女生[i]与女生[i-1]之间(剩余的)男生的个数 a[i]:=tmp1-tmp2; tmp2:=tmp1; k:=i; while a[k]=0 do dec(k); //k指距离最近的 有剩余男生的a[i] write(i-k+1,' '); //间隔女生数=间隔男生数 a[k]:=a[k]-1; end; end.
-
02016-04-06 17:47:21@
测试数据 #0: Accepted, time = 15 ms, mem = 560 KiB, score = 10
测试数据 #1: Accepted, time = 15 ms, mem = 564 KiB, score = 10
测试数据 #2: Accepted, time = 0 ms, mem = 560 KiB, score = 10
测试数据 #3: Accepted, time = 0 ms, mem = 564 KiB, score = 10
测试数据 #4: Accepted, time = 0 ms, mem = 564 KiB, score = 10
测试数据 #5: Accepted, time = 0 ms, mem = 564 KiB, score = 10
测试数据 #6: Accepted, time = 0 ms, mem = 560 KiB, score = 10
测试数据 #7: Accepted, time = 0 ms, mem = 564 KiB, score = 10
测试数据 #8: Accepted, time = 0 ms, mem = 564 KiB, score = 10
测试数据 #9: Accepted, time = 0 ms, mem = 564 KiB, score = 10
Accepted, time = 30 ms, mem = 564 KiB, score = 100 -
02015-09-06 20:14:56@
import java.io.*;
import java.math.BigInteger;
import java.util.Scanner;
import java.util.Stack;
import java.awt.*;public class Main {
public static int[] a=new int[30002];
public static void main(String[] args) {
Scanner cin=new Scanner(System.in);
int n=cin.nextInt();
int i;
int m=0;
for(i=0;i<n;i++)
{m=cin.nextInt();
a[m+i]=-1;}
Stack stack=new Stack<>();
for(int j=0;j<m+n;j++)
{if(a[j]==0)
{a[j]=j;
stack.push(a[j]);}
else if(a[j]==-1&&!stack.empty())
{a[j]=j;
if(a[j]-(int)stack.peek()==1)
{
System.out.print(1+" ");
stack.pop();}
else
{
int p=(a[j]-(int)stack.peek()-1)/2;System.out.print(a[j]-(int)stack.pop()-p+" ");
}
}
}
}
}
-
02015-08-31 14:46:34@
直接栈模拟
代码
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>using namespace std;
template<typename T>
void print(const T *p, const T *q,string gap = "") {
int d = p < q ? 1 : -1;
while(p != q) {
cout << *p;
p += d;
if(p != q) {
cout << gap;
}
}
cout << endl;
}template<typename T>
void print(const T a,string gap = "") {
int len = gap.length();
if(len >= 2) cout << gap[0] << a << gap[1] << endl;
else cout << a << endl;
}#define fillchar(a, b) memset(a, b, sizeof(b))
const int MAXN = 2e6;
const int MAXM = 1;
int stack[MAXN], top, n;
int A[MAXN], B[MAXN], bp;int main() {
//freopen("D://imput.txt", "r", stdin);
while(cin >> n) {
for(int i = 1 ; i <= n; i ++) {
cin >> A[i];
}
top = -1,bp = 0;
int vp = 1, np = 1;
while(vp <= n) {
if(A[vp] > bp) {
stack[++ top] = np;
B[bp ++] = np ++;
} else {
int l = stack[top --];
int r = np;
l = lower_bound(B, B + bp, l) - B;
r = lower_bound(B, B + bp, r) - B;
cout << r - l;
if(vp == n){
cout << endl;
}
else cout << " ";
np ++,vp ++;
}
}
}
return 0;
} -
02015-02-12 20:54:15@
神坑啊。。。。数据9目测男生比女生多几倍。。。。。难道说?!!!
#include<iostream>
#include<cstdio>
using namespace std;
const int maxn=50000;
int k[maxn]={0};
int numn;
int main()
{
scanf("%d",&numn);int x=0,y=0;
for(int i=1;i<=numn;i++)
{
scanf("%d",&x);
for(int j=y+i;j<=x+i-1;j++)k[j]=1;
int c=0;
for(int j=x+i-1;j>=1;j--)
{
if(k[j]==1)
{
k[j]=-1;
printf("%d ",c+1);break;
}
else if(k[j]==-1)c++;
}y=x;
}
printf("\n");
return 0;
} -
02015-01-25 00:31:32@
女生并非n个,只多不少,但是题目只需要求前n个女生的伴距离她多远
-
02015-01-25 00:27:53@
其实题目并非只有2*n个人,甚至更多,但是题目只要求那n个女孩的伴距离她多远
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <math.h>
#include <vector>
#include <cstdio>
#include <string>
#include<string.h>
#include <fstream>
#include <iostream>
#include <algorithm>
using namespace std;
#define exp 1e-8
#define INF 100000000
#define set(a,b) memset(a,b,sizeof(a));
void bug(string st="bug")
{cout<<st<<endl;}
bool sex[310000];
int sum[310000];
int main()
{
int n;
cin>>n;
int temp,num=0,idx=0;
int maxn=0;
for(int i=1;i<=n;i++)
{
cin>>temp;
idx=idx+temp-num+1;
sex[idx]=1;
sum[idx]=temp;
num=temp;
maxn=temp;//必须找到那个最后一个女生id
}
int cnt=1;
stack<int>sta;
for(int i=1;i<=2*temp;i++)
{
if(sex[i]==0)
sta.push(cnt++);
if(sex[i]==1)
{
int temp=sta.top();
sta.pop();
cout<<sum[i]-temp+1<<" ";
}
}
return 0;
} -
02014-10-16 10:57:02@
用什么栈呢?
随便摸拟不就行了:
#include <cstdio>
#define N 2000using namespace std;
int n, a[N], b[N];
int main()
{
scanf("%d", &n);
for (int i = 1; i <= n; ++i)
{
scanf("%d", &a[i]);
b[i] = a[i] - a[i-1];
}
for (int i = 1; i <= n; ++i)
{
for (int j = i; j; j--)
if (b[j])
{
printf("%d ", a[i]-a[j-1]-b[j]+1);
b[j]--; break;
}
}
return 0;
} -
02014-03-11 21:00:16@
大家注意 最后一个数据不一定是n啊!!!
比如:6
4 5 6 6 6 7
如下程序就过了:
var n,i,j,k,ss,t,a,top:longint;s:ansistring;
p:array[0..300000]of longint;
begin
readln(n);ss:=0;s:='';t:=0;top:=0;fillchar(p,sizeof(p),0); for i:=1 to n do begin read(a);k:=a-ss;ss:=a; for j:=1 to k do s:=s+'1'; s:=s+'2'; end; //writeln(s);
for i:=1 to length(s) do if s[i]='1' then begin inc(top);p[top]:=i;end else begin inc(t); if t<>1 then write(' '); write((i-p[top])div 2+1);dec(top); end; end.
我就被keng了5次 -
02014-03-11 19:49:27@
大家注意 最后一个数据不一定是n啊!!!
比如:6
4 5 6 6 6 7
如下程序就过不了:var n,i,j,k,ss,t,a,top:longint;s:ansistring;
p:array[0..300000]of longint;
begin
readln(n);ss:=0;s:='';t:=0;top:=0;fillchar(p,sizeof(p),0);
for i:=1 to n do
begin
read(a);k:=a-ss;ss:=a;
for j:=1 to k do s:=s+'1';
s:=s+'2';
end;
//writeln(s);
for i:=1 to length(s) do
if s[i]='1' then
begin inc(top);p[top]:=i;end
else begin
inc(t);
if t<>1 then write(' ');
write((i-p[top])div 2+1);dec(top);
end;
end.
我就被keng了5次 -
02013-08-25 20:11:33@
我很无辜的写了2kb的模拟代码。。。
0分。。
后来看了别人的代码
短短几行,满分,有吐血的冲动。。 -
02013-08-21 00:31:27@
求大神指点为毛会有一个RE。。。
#include<iostream>
#include<stack>
#include<cstdio>
#include<cstring>
using namespace std;
bool isboy(int a){
if(a%2==0){
return false;
}else{
return true;
}
}
int main()
{
stack<int> s;
int n;
cin>>n;
int cs[2*n+1];
int zn[n];
int mb[2*n+1];
memset(mb,0,sizeof mb);
for(int i=1;i<=2*n;i++){
cs[i]=i;
}
for(int i=1;i<=n;i++) cin>>zn[i];
int b=0,z=1,sy=1,mbsy=1;
while(b<=n){
zn[z]=zn[z]-b;
while(zn[z]>0){
if(isboy(cs[sy])){
mb[mbsy++]=cs[sy++];
b++;
zn[z]--;
}else{
s.push(cs[sy++]);
}
}
s.push(cs[sy++]);
do{
mb[mbsy++]=s.top();
s.pop();
}while(b==zn[++z]);
}
for(int i=1;i<=2*n;i++){
if (!isboy(mb[i])){
for(int i2=1;i2<i;i2++)
if(mb[i2]==mb[i]-1){
int ns=0;
for(int i3=i2;i3<i;i3++)
if(isboy(mb[i3])) ns++;
cout<<ns<<' ';
break;
break;
}
}
}
return 0;
} -
02013-02-16 10:18:21@
-
02012-07-29 15:12:46@
弱菜的我写了这么长。。。
还是蛮好想的,表示我把它当模拟写了。
program vijos1062;
var
head,tail,n,i,j,now,cal,k:longint;
ans:array[1..1500] of longint;
data:array[0..1500] of longint;
flag:boolean;begin
readln(N);
now:=0;
for i:=1 to n do
begin
read(data[i]);
end;
readln;
now:=1;
for i:=1 to n do
begin
cal:=data[i];
k:=i-1;
if data[i]=data then
begin
flag:=false;
while not(flag) do
begin
if data[k]=data[i] then
begin
dec(cal);
dec(k);
end;
if (data[i]data[k]) and (data[i]-data[k]>data[i]-cal) then
flag:=true;
if (data[i]data[k]) and (data[i]-data[k] -
02012-07-24 16:07:16@
数组一定要开大大大大大大大啊!~~~!!!
只要空间不溢出,开到3000000吧..题目意思读不懂的可以看看这里,input是指每个女生左边的男生数
可以把男生看成"" (参看楼下的)
就问每个女生">"相隔 多少个 已经配对""才能找到属于自己的" -
02012-08-02 10:14:57@
├ 测试数据 01:答案正确... 0ms
├ 测试数据 02:答案正确... 0ms
├ 测试数据 03:答案正确... 0ms
├ 测试数据 04:答案正确... 0ms
├ 测试数据 05:答案正确... 0ms
├ 测试数据 06:答案正确... 0ms
├ 测试数据 07:答案正确... 0ms
├ 测试数据 08:答案正确... 0ms
├ 测试数据 09:答案正确... 0ms
├ 测试数据 10:答案正确... 0ms
---|---|---|---|---|---|---|---|-
Accepted 有效得分:100 有效耗时:0ms点击这里查看
不是说1500个女的吗,为什么一定要把数组开这么大才能过,耗我AC率
-
02010-07-05 17:45:56@
一对舞伴 就像 bigen 和 end 这样 讲 应该 对吧,,,,
男的是 bigen 在左边 (pascal)
然后 开个hash 搞定 -
02010-04-05 20:37:56@
var
a:array[1..10000000] of longint;
i,j,k,f,t,n,x:longint;
begin
readln(n);
k:=0;
f:=0;
for i:=1 to n do begin
read(x);
while f -
02009-11-10 20:06:34@
var
a:array[0..2000]of boolean;
i,k,t,n:integer;
begin
readln(n); fillchar(a,sizeof(a),false);
for i:=1 to n do a[i]:=true;
for i:=1 to n do
begin
read(k); t:=k;
while not a[t] do dec(t);
a[t]:=false; write(k+1-t,' ');
end;end.
简单得很 具体的 还……