| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
为什么c++提交WA,G++提交就过了,真奇葩,害我找了半天错,贴下代码:#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
const int maxn = 500;
const int maxn1 = 500;
int a[maxn];
int m;
void change()
{
int b[maxn1];
int vis[maxn1];
int i,j;
int location;
int temp;
int k;
int pos;
int cnt;
memset(b,-1,sizeof(b));
memset(vis,0,sizeof(vis));
/*for(i=0;i<300;i++)
{
b[i] = -1;
}
for(i=0;i<300;i++)
{
vis[i] = 0;
}*/
temp = 0;
cnt = 0;
for(i=0;i<m;i++)
{
location = a[i] + i;
for(j=temp;j<=location;j++)
{
b[j] = 0;
temp = location + 1;
}
b[location] = 1;
}
k = 0;
while(b[k] != -1)
{
k++; //0,1一共的个数
}
for(i=0;i<k;i++)
{
if(b[i] == 1)
{
for(j=i-1;j>=0;j--)
{
if(b[j] == 0 && vis[j] == 0)
{
vis[i] = 1;
vis[j] = 1;
pos = i-j+1;
cnt++;
if(cnt == 1)
cout<<pos/2;
else
cout<<" "<<pos/2;
break;
}
}
}
}
cout<<endl;
}
int main()
{
int T;
int i;
freopen("111","r",stdin);
cin>>T;
while(T--)
{
cin>>m;
for(i=0;i<m;i++)
{
cin>>a[i];
}
change();
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator