CSP-M1 B title

Meaning of the questions:
Cuckoo East exam week, and a total of n-day test on Monday. He did not want to exam week so tired, I intended to have a nice dinner every meal. He decided to eat fried every day, cuckoo East ai need to buy a fried every day. But fried shops in order to stimulate consumption, buy only two methods: 1, one day at a one-time buy two fried. 2, buy a fried today, but for tomorrow to buy a fried, the store will give a ticket, the next day to come and collect tickets. There is no other way to buy, you can use two ways to buy numerous times, but the East is a thrifty cuckoo child, he left the end of exam week, when the hands of a ticket does not allow end. Cuckoo East very rich, you do not need to worry about money East cuckoo, cuckoo East but stupid, he would like to ask you if he could have just bought a fried ai day exam week.
input:
Enter the number of exam Zhou
enter the number of exam week fried ai day.
output:
If you can enter "YES", otherwise a "NO".
the INPUT the Sample:
4
1 2 1 2
the Sample the Output:
YES
ideas:
can be drawn if the number is an even number of fried buy direct purchase using the first method, the next day will not be affected by the meaning of the questions, if it is an odd number, then ai-1 before first use of a later one embodiment, a last embodiment the use of a second later, the next day the number of fried at this time should be required for later 1. Save determination, when the method using the above judgment, if occurred the day before the day affected such that ai is less than 0, then the output "NO". The final judgment, if the last day of the remaining number of fried at not affect the previous day by all even, then the case 2 has no coupons hand, output "YES", and otherwise outputs "NO".
Code:

#include<iostream>
using namespace std;
int main()
{
 int n;
 cin>>n; 
 int *v=new int[n+1]; 
 for(int i=0;i<n;i++)
 {
  cin>>v[i];
 }
 for(int i=0;i<n-1;i++)
 {
  if(v[i]%2==1)
  {
   v[i+1]=v[i+1]-1;
  }
  if(v[i]<0)
  {
   cout<<"NO";
   return 0;
  }
  else if(v[i]%2==0)
  {
   v[i+1]=v[i+1];
  }
  //if(v[n])
 }
 if(v[n-1]%2==0)
    cout<<"YES";
 else
    cout<<"NO";
 return 0;
} 
Published 19 original articles · won praise 0 · Views 213

Guess you like

Origin blog.csdn.net/weixin_45117273/article/details/104982453