2.25 Test Replay

description

You now have n digits, you can delete one of the digital number of the remaining arranged in the original order, and then the number of bits of the even and odd bit numbers are equal, the number can be removed any, has asked how many cases make it equal.

data range

1 <= n <= 2e5
ai <= 1e4

Export

Output How many cases make it equal

Thinking

To do this question yesterday, it may be said that the subject is not clear, it may be my understanding errors, that is, after he deleted a number of elements remaining positions will not move forward, the fact is yes. In fact, this problem is the use of a parity study it, the key is how you deal with the remaining elements of the parity change after deleting a number.

#include<iostream> 
#include<algorithm>
#include<cstdio>
using namespace std;
int a[200020],b[2],d[2];
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
       cin>>a[i];
       b[i%2]+=a[i];//我一开始看到这个~妙啊~  存奇数和偶数和
    }
    int cnt=0;
    for(int i=1;i<=n;i++)//每个元素都可能被删掉,都模拟一遍
    {
       d[(i-1)%2]+=a[i-1];//记录删了之后奇偶性改变后的奇数偶数和
       b[i%2]-=a[i];//在原来的奇偶数和当中删去当前元素
       //可能有人这里看不懂,我当时也看不懂嘻嘻
       //这里的d数组记录的就是删除元素 前面 的奇偶数和,d数组就是删除元素后面的
       //删除元素前移后原本是奇位就变成偶位了所以是b[0]和d[1]这样的搭配
       if(b[0]+d[1]==b[1]+d[0])
  	    cnt++;
    }
 	cout<<cnt<<endl;
}

description

After learning that the main group AC hair red hair poor, the rich Poems decided to sponsor this week an interesting activity. So today, after you AC will still receive a red envelope, red envelopes this exclusive sponsor of the cost of long-legged beauty school bully goddess week Poems. Poems week although the money, but still like to grab a red envelope, based on her years of experience to grab a red envelope, she can always grab a certain percentage of the amount. Today Week Poems intends to purse a yuan distributed to you, grab a red envelope based on many years of experience Poems week, she summed up every 1 dollar she could snatch away the 1 / b money. After weeks of Poems wealthy, when one yuan each time the balance of weeks Poems of greater than or equal, she would integer money part sent out until finally she did not have enough money to be made, so she was very curious about her in the end made a total of how much money ?

Entry

Input contains two integers a and b (1≤a≤1000; 2≤b≤1000)

Export

She made a total of how much money

Thinking

The key is thickened portion of the title, I just did not understand here, in fact, this is a simple simulation.
The integer part of the money sent out, the fractional part is in my possession, it may Couchu piece, I direct lost.

#include<cstdio>
#include<iostream>
using namespace std;
int main()
{
 int a,b;
 while(cin>>a>>b)
 {
  int sum=0;
  double res=a*1.0;//res记录的是我拥有的钱数
  while(res>=1)//只要我还有一块钱我还是会发红包的
  {
         a=(int)res;//每次发整数部分的
         sum+=a;//记录一下我发了多少
         res=res-(double)a+(double)(a/b); //更新钱数,减去发的加上抢的
  } 
  cout<<sum<<endl;
 } 
} 

description

Yong sister school winter vacation want to learn to cook, and today he decided to soup, which requires exactly n liters of water
nearby shops are only two bottles - a 1-liter bottles and two 2-liter bottle has an infinite number of bottles.
The first cost kinds of bottle as a, b for the cost of the second bottle
Yong sister very virtuous, he want to spend the least money to buy just hold n liters of water bottles
you need to answer q independent inquiry.

Entry

The first line has an integer q (1≤q≤500) -. The number of queries
q behavior below n, a, b (1≤ni≤1e12,1≤ai, bi≤1000) respectively, the volume of water, two kind of bottle price

Export

Q output lines, each an integer, respectively corresponding to each row minimum cost

Thinking

What a start to see an infinite number of different prices, full, thought it was a backpack full of it.
In fact must use a bottle of thinking is a problem, look at the price of two bottles of one liter of water and a bottle of two liters of water which is more expensive, which cost a thing which, but required by law to fill, so the total number is odd water liters of water.

#include<cstdio>
#include<iostream>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        long long n,a,b,ans=0;
        cin>>n>>a>>b;
        if(2*a<b)//如果两瓶一升水比一瓶两升水便宜
            ans=a*n;
        else if(2*a>=b) 
        {
            if(n%2==1)
    		ans=b*(n/2)+a;
            else
   		 ans=b*(n/2);    
        }
        cout<<ans<<endl;
    }
}

The rest of the time to write the next reason

Published 32 original articles · won praise 5 · Views 868

Guess you like

Origin blog.csdn.net/LebronGod/article/details/104512462