10930 - A-Sequence
Moderator: Board moderators
-
- Experienced poster
- Posts: 111
- Joined: Mon Jan 09, 2006 6:19 pm
- Location: Tehran, Iran
- Contact:
-
- New poster
- Posts: 31
- Joined: Sat Apr 01, 2006 6:24 am
- Contact:
-
- New poster
- Posts: 10
- Joined: Sat Aug 19, 2006 7:23 pm
- Location: bangladesh
- Contact:
10930 - A-Sequence
i am getting wa in 10930. i saw all the post in the board but getting the same result. hope u will help me to get it AC.
here is my code:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define sz 30010
int comp_fun(const void *a, const void *b){
int *x=(int*) a;
int *y =( int* ) b;
int m= *x;
int n= *y;
return ( m - n );
}
void main(){
int array [sz],n,num[40],sum,i,j,cas=0,flag;
//freopen("10930.txt","w",stdout);
while ( scanf ( "%d" , &n ) == 1 ) {
memset( array, 0 , sizeof (array) );
sum = flag = 0 ; cas++ ;
printf ( "Case #%d:", cas );
for( i=0 ; i<n ; i++ ) {
scanf( "%d" , &num );
printf(" %d",num);
}
qsort(num , n , sizeof( int ),comp_fun);
for( i = 0 ; i<n ; i++){
array[ num ]++;
for( j=0 ; j < num ; j++ ) {
if( array[j] != 0 ) {
sum = num + j ;
array[ sum ]++ ;
}
}
}
for(j=0;j<sz;j++)
if(array[j]>=2){
flag=1;
break;
}
if(flag)
printf("\nThis is not an A-sequence.\n");
else
printf("\nThis is an A-sequence.\n");
}
}
here is my code:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define sz 30010
int comp_fun(const void *a, const void *b){
int *x=(int*) a;
int *y =( int* ) b;
int m= *x;
int n= *y;
return ( m - n );
}
void main(){
int array [sz],n,num[40],sum,i,j,cas=0,flag;
//freopen("10930.txt","w",stdout);
while ( scanf ( "%d" , &n ) == 1 ) {
memset( array, 0 , sizeof (array) );
sum = flag = 0 ; cas++ ;
printf ( "Case #%d:", cas );
for( i=0 ; i<n ; i++ ) {
scanf( "%d" , &num );
printf(" %d",num);
}
qsort(num , n , sizeof( int ),comp_fun);
for( i = 0 ; i<n ; i++){
array[ num ]++;
for( j=0 ; j < num ; j++ ) {
if( array[j] != 0 ) {
sum = num + j ;
array[ sum ]++ ;
}
}
}
for(j=0;j<sz;j++)
if(array[j]>=2){
flag=1;
break;
}
if(flag)
printf("\nThis is not an A-sequence.\n");
else
printf("\nThis is an A-sequence.\n");
}
}
-
- New poster
- Posts: 10
- Joined: Sat Aug 19, 2006 7:23 pm
- Location: bangladesh
- Contact:
another WA.now without sort.
thanks for yr (respected Thowid) reply.
my modified code:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define sz 30010
void main(){
int array [sz],n,num[40],sum,i,j,cas=0,flag,pre_num;
while ( scanf ( "%d" , &n ) == 1 ) {
pre_num = 0;
memset( array, 0 , sizeof (array) );
sum = flag = 0 ; cas++ ;
printf ( "Case #%d:", cas );
for( i=0 ; i<n ; i++ ) {
scanf( "%d" , &num );
if(num <= pre_num)
flag= 1;
pre_num = num;
printf(" %d",num);
}
if(!flag){
for( i = 0 ; i<n ; i++){
array[ num ]++;
for( j=0 ; j < num ; j++ ) {
if( array[j] != 0 ) {
sum = num + j ;
array[ sum ]++ ;
}
}
}
for(j=0;j<sz;j++)
if(array[j]>=2){
flag=1;
break;
}
}
if(flag)
printf("\nThis is not an A-sequence.\n");
else
printf("\nThis is an A-sequence.\n");
}
}
thanks for yr (respected Thowid) reply.
my modified code:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define sz 30010
void main(){
int array [sz],n,num[40],sum,i,j,cas=0,flag,pre_num;
while ( scanf ( "%d" , &n ) == 1 ) {
pre_num = 0;
memset( array, 0 , sizeof (array) );
sum = flag = 0 ; cas++ ;
printf ( "Case #%d:", cas );
for( i=0 ; i<n ; i++ ) {
scanf( "%d" , &num );
if(num <= pre_num)
flag= 1;
pre_num = num;
printf(" %d",num);
}
if(!flag){
for( i = 0 ; i<n ; i++){
array[ num ]++;
for( j=0 ; j < num ; j++ ) {
if( array[j] != 0 ) {
sum = num + j ;
array[ sum ]++ ;
}
}
}
for(j=0;j<sz;j++)
if(array[j]>=2){
flag=1;
break;
}
}
if(flag)
printf("\nThis is not an A-sequence.\n");
else
printf("\nThis is an A-sequence.\n");
}
}
altaf hussain(sust_2002) wrote:
for( i = 0 ; i<n ; i++){
array[ num ]++;
for( j=0 ; j < num ; j++ ) {
if( array[j] != 0 ) {
sum = num + j ;
array[ sum ]++ ;
}
}
}
}
I think this doesn't work correctly. Try the input:
Code: Select all
5 1 6 8 10 12
From 0 to 0
-
- New poster
- Posts: 10
- Joined: Sat Aug 19, 2006 7:23 pm
- Location: bangladesh
- Contact:
i am still getting WA. Please help!!!
here my code:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define sz 30010
void main(){
int array [sz],n,num[40],sum,Max,i,j,cas=0,flag,pre_num;
while ( scanf ( "%d" , &n ) == 1 ) {
pre_num = Max=0;
memset( array, 0 , sizeof (array) );
sum = flag = 0 ; cas++ ;
printf ( "Case #%d:", cas );
for( i=0 ; i<n ; i++ ) {
scanf( "%d" , &num );
if(num <= pre_num)
flag= 1;
pre_num = num;
printf(" %d",num);
}
if(!flag){
for( i = 0 ; i<n ; i++){
array[ num ]++;
for( j=0 ; j < num ; j++ ) {
if( array[j] != 0 ) {
sum = num + j ;
array[ sum ]++ ;
}
}
}
for(j=0;j<= pre_num;j++)
//if(array[ j]!=0)
// printf("a [ %d]= %d",j,array[j]);
if(array[j]>=2){
flag=1;
break;
}
}
if(flag)
printf("\nThis is not an A-sequence.\n");
else
printf("\nThis is an A-sequence.\n");
}
}
here my code:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define sz 30010
void main(){
int array [sz],n,num[40],sum,Max,i,j,cas=0,flag,pre_num;
while ( scanf ( "%d" , &n ) == 1 ) {
pre_num = Max=0;
memset( array, 0 , sizeof (array) );
sum = flag = 0 ; cas++ ;
printf ( "Case #%d:", cas );
for( i=0 ; i<n ; i++ ) {
scanf( "%d" , &num );
if(num <= pre_num)
flag= 1;
pre_num = num;
printf(" %d",num);
}
if(!flag){
for( i = 0 ; i<n ; i++){
array[ num ]++;
for( j=0 ; j < num ; j++ ) {
if( array[j] != 0 ) {
sum = num + j ;
array[ sum ]++ ;
}
}
}
for(j=0;j<= pre_num;j++)
//if(array[ j]!=0)
// printf("a [ %d]= %d",j,array[j]);
if(array[j]>=2){
flag=1;
break;
}
}
if(flag)
printf("\nThis is not an A-sequence.\n");
else
printf("\nThis is an A-sequence.\n");
}
}
altaf hussain(sust_2002) wrote: for( j=0 ; j < num ; j++ ) {
if( array[j] != 0 ) {
sum = num + j ;
array[ sum ]++ ;
}
}
}
}
Still problem here. Try
Code: Select all
1 6 8 10 25
From 0 to 0
hey !
i dont know what to do ..... i applied a very straight forward method and passed all the test cases. I was afraid to get TLE but it got WA!!!
I cant have any clue ... is there anyone to help?
i dont know what to do ..... i applied a very straight forward method and passed all the test cases. I was afraid to get TLE but it got WA!!!
I cant have any clue ... is there anyone to help?
Code: Select all
cut after AC
Last edited by Kallol on Wed Aug 30, 2006 10:37 am, edited 1 time in total.
Syed Ishtiaque Ahmed Kallol
CSE,BUET
Bangladesh
CSE,BUET
Bangladesh
-
- A great helper
- Posts: 481
- Joined: Sun Jun 19, 2005 1:18 am
- Location: European Union (Slovak Republic)
well,
i submitted the same code without sorting , but again i got a WA. I myself dont have any reason to sort the sequence. After getting WA without sorting , I found in one of the threads here that someone got AC with sorting. So, I sorted it. Anyway now my code looks like as follows:
can you guess why is it getting WA?
i submitted the same code without sorting , but again i got a WA. I myself dont have any reason to sort the sequence. After getting WA without sorting , I found in one of the threads here that someone got AC with sorting. So, I sorted it. Anyway now my code looks like as follows:
can you guess why is it getting WA?
Code: Select all
cut after AC
Last edited by Kallol on Wed Aug 30, 2006 10:36 am, edited 1 time in total.
Syed Ishtiaque Ahmed Kallol
CSE,BUET
Bangladesh
CSE,BUET
Bangladesh
I told you to change the condition. Now that they are not sorted, will this work?
Code: Select all
if(N[i]==N[i-1])...
Hi Darko!
I got ur point ! I have changed my code for equality check but still cnat get rid of WA!
here it is..
I got ur point ! I have changed my code for equality check but still cnat get rid of WA!
here it is..
Code: Select all
cut after AC
Last edited by Kallol on Wed Aug 30, 2006 10:36 am, edited 1 time in total.
Syed Ishtiaque Ahmed Kallol
CSE,BUET
Bangladesh
CSE,BUET
Bangladesh