Again WA!!brianfry713 wrote:Don't print a space at the end of the sequence.
10930 - A-Sequence
Moderator: Board moderators
-
- New poster
- Posts: 36
- Joined: Sun Mar 18, 2012 8:18 am
Re: 10930 why RE??
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10930 why RE??
Post your updated code.
Check input and AC output for thousands of problems on uDebug!
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10930 why RE??
This code doesn't compile, you're missing the { after main().
Check input and AC output for thousands of problems on uDebug!
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10930 why RE??
Input: 2 2 1
is not an A-sequence.
Add a post when you update your code.
is not an A-sequence.
Add a post when you update your code.
Check input and AC output for thousands of problems on uDebug!
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10930 why RE??
brianfry713 wrote:Input: 2 2 1
is not an A-sequence.
Check input and AC output for thousands of problems on uDebug!
Re: 10930 why RE??
Thank Brianfrybrianfry713 wrote:brianfry713 wrote:Input: 2 2 1
is not an A-sequence.
![:)](./images/smilies/icon_smile.gif)
-
- New poster
- Posts: 6
- Joined: Sat Dec 01, 2012 2:52 pm
Re: 10930 - A-Sequence
1 TL and 8 WA ..
and i can't find why :@ ..
does arr[1] MUST BE 1 or it just have to be increasingly-ordered ?
that's my code ..
any help ?
and i can't find why :@ ..
does arr[1] MUST BE 1 or it just have to be increasingly-ordered ?
that's my code ..
Code: Select all
//WA :(
#include <iostream>
#include <map>
using namespace std;
bool A_Seq;
int Size;
int arr[35];
void Dispaly_arr()
{
for (int i = 0; i < Size; ++i)
{
cout << arr[i];
if (i != Size - 1) cout << " ";
}
cout << endl;
}
int main ()
{
//freopen ("in.txt", "r", stdin);
//freopen ("out.txt", "w", stdout);
int T = 0;
while (cin >> Size)
{
map <int, int> Sums;
A_Seq = true;
for (int i = 0; i < Size; ++i)
{
cin >> arr [i];
if ((i && arr [i] <= arr [i-1]) || arr [i] < 1) A_Seq = false;
else Sums[arr[i]] = 1;
}
//if (arr[0] != 1) A_Seq = false;
if (A_Seq)
{
for (int i = 0; i < Size; ++i)
{
for (int j = i+1; j < Size; ++j)
{
int sum = arr[i]+arr[j];
++Sums[sum];
if (Sums[sum] > 1)
{
A_Seq = false;
break;
}
}
if (!A_Seq) break;
}
}
//Case #2: 1 2 3
cout << "Case #"<<++T<<": ";
Dispaly_arr();
if (A_Seq) cout << "This is an A-sequence." << endl;
else cout << "This is not an A-sequence." << endl;
}
return 0;
}
any help ?
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10930 - A-Sequence
Input:AC output:
Code: Select all
4 2 3 7 8
Code: Select all
Case #1: 2 3 7 8
This is an A-sequence.
Check input and AC output for thousands of problems on uDebug!
-
- New poster
- Posts: 6
- Joined: Sat Dec 01, 2012 2:52 pm
Re: 10930 - A-Sequence
@ brianfry713: thanx man, i've finally solve it, but i used a Backtracking method ![:D](./images/smilies/icon_biggrin.gif)
thanx again ..
![:D](./images/smilies/icon_biggrin.gif)
thanx again ..
-
- New poster
- Posts: 49
- Joined: Mon Jun 16, 2014 7:40 pm
Re: 10930 - A-Sequence
Hiii, I m getting wrong ans continuosly. I have checked the output for all the previous inputs given in the board and and i m getting the expected output. plz help
Thanx
Thanx
Code: Select all
#include<cstdio>
using namespace std;
int sequence(int a[],int n)
{
int i,j,k,sum;
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
sum=a[i]+a[j];
if(sum==a[n])
return 0;
for(k=j+1;k<n;k++)
{
if(sum+a[k]>a[n])
break;
else sum=sum+a[k];
if(sum==a[n])
return 0;
}
}
}
return 1;
}
int main()
{
int d,i,arr[40],flag,c=0;
while(scanf("%d",&d)==1)
{
c++;
flag=1;
for(i=0;i<d;i++)
{
scanf("%d",&arr[i]);
if(i!=0)
if(arr[i]<=arr[i-1])
flag=0;
}
if(flag)
{
for(i=0;i<d;i++)
{
flag=sequence(arr,i);
if(flag==0)
break;
}
}
printf("Case #%d:",c);
for(i=0;i<d;i++)
printf(" %d",arr[i]);
if(flag)
printf("\nThis is an A-sequence.\n");
else
printf("\nThis is not an A-sequence.\n");
}
return 0;
}
Re: 10930 - A-Sequence
Input
Acc Output
Got accepted now by DP. Then I read posts in this thread. Some people misunderstood problem description. There is no need in sorting. If input is not sorted we should print that it is not A-sequence. Else check for sums.
Code: Select all
6 1 2 5 10 14 21
7 1 2 5 10 14 23 36
Code: Select all
Case #1: 1 2 5 10 14 21
This is not an A-sequence.
Case #2: 1 2 5 10 14 23 36
This is not an A-sequence.
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman
-
- New poster
- Posts: 18
- Joined: Wed Dec 17, 2014 9:44 pm
Re: 10930 - A-Sequence
I've tried every possible input from here and udebug. Still getting WA. No idea what's wrong. Help me...
Here's the code....
Here's the code....
Code: Select all
#include<bits/stdc++.h>
#define sc(x) scanf("%d",&x)
#define sc2(x,y) scanf("%d%d",&x,&y)
#define scs(x) scanf("%s",x)
#define pr(x) printf("%d",x)
#define prn(x) printf("%d\n",x)
#define memc(x,y) memcpy(&x,&y,sizeof(x))
#define mems(x,y) memset(x,y,sizeof(x))
#define fli() freopen("in.txt","r",stdin)
#define flo() freopen("out.txt","w",stdout)
#define rep(i,v) for(int i=0;i<v;i++)
#define repe(i,v) for(int i=0;i<=v;i++)
#define Rep(i,x,v) for(int i=x;i<v;i++)
#define Repe(i,x,v) for(int i=x;i<=v;i++)
#define repv(i,x) for(auto i=x.begin();i!=x.end();i++)
#define reprv(i,x) for(auto i=x.rbegin();i!=x.rend();i++)
#define what_is(x) cerr << #x << " : " << x << endl
#define pb push_back
#define bl putchar('\n')
#define gcc getchar()
#define pcc putchar
#define si size
#define fi first
#define se second
#define MAX 1010
typedef long long ll;
typedef unsigned long long ull;
typedef std::vector<int> vi;
typedef std::pair<int,int> ii;
using namespace std;
int a[35],idx,sum[MAX],tidx,tsum[MAX];
bool dp[MAX];
int main(){
// fli();
// flo();
int n,test_no=1;
bool flag;
while(sc(n)==1){
flag=true;
printf("Case #%d:",test_no++);
rep(i,n){
sc(a[i]);
printf(" %d",a[i]);
if(i and a[i]<=a[i-1]){
flag=false;
}
}bl;
if(a[0]<1) flag=false;
mems(dp,0);
mems(sum,0);
idx=0;
rep(i,n){
if(dp[a[i]] or !flag){
flag=false;
break;
}
tidx=0;
rep(j,idx){
if(a[i]+sum[j]<=1000){
dp[a[i]+sum[j]]=1;
tsum[tidx++]=a[i]+sum[j];
}
}
sum[idx++]=a[i];
dp[a[i]]=1;
rep(j,tidx){
sum[idx++]=tsum[j];
}
}
if(flag){
puts("This is an A-sequence.");
}else{
puts("This is not an A-sequence.");
}
}
return 0;
}