Nicholas, a painter is going to paint several new canvases. Nicholas is sure that the canvases will turn out so great that each one will need framing and being hung on the wall. Frames are what Nicholas decided to begin with. Nicholas has n sticks whose lengths equal a 1, a 2, … a n . Nicholas does not want to break the sticks or glue them together. To make a h × w -sized frame, he needs two sticks whose lengths equal h and two sticks whose lengths equal w . Specifically, to make a square frame (when h = w ), he needs four sticks of the same length. Now Nicholas wants to make from the sticks that he has as many frames as possible; to be able to paint as many canvases as possible to fill the frames. Help him in this uneasy task. Note that it is not necessary to use all the sticks Nicholas has.

区块链毕设网qklbishe.com为您提供问题的解答

Nicholas, a painter is going to paint several new canvases. Nicholas is sure that the canvases will turn out so great that each one will need framing and being hung on the wall. Frames are what Nicholas decided to begin with.

Nicholas has n sticks whose lengths equal a 1, a 2, … a n . Nicholas does not want to break the sticks or glue them together. To make a h × w -sized frame, he needs two sticks whose lengths equal h and two sticks whose lengths equal w . Specifically, to make a square frame (when h = w ), he needs four sticks of the same length.

Now Nicholas wants to make from the sticks that he has as many frames as possible; to be able to paint as many canvases as possible to fill the frames. Help him in this uneasy task. Note that it is not necessary to use all the sticks Nicholas has.

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
 
int main()
{
    int n,i,temp;
    int count;
    int flag;
    int a[101];
    for(i=0;i<101;i++)
    {
        a[i]=0;
    }
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&temp);
        a[temp]++;
    }
    flag=0;
    count=0;
    for(i=0;i<101;i++)
    {
        if(a[i]>=2)
        {
            a[i]-=2;
            if(flag<2)
            {
                flag++;
            }
            if(flag==2)
            {
                count++;
                flag=0;
            }
            if(a[i]>=2)
            {
                i–;
            }
        }
    }
    printf("%dn",count);
    return 0;
}
49:14

以上就是关于问题Nicholas, a painter is going to paint several new canvases. Nicholas is sure that the canvases will turn out so great that each one will need framing and being hung on the wall. Frames are what Nicholas decided to begin with. Nicholas has n sticks whose lengths equal a 1, a 2, … a n . Nicholas does not want to break the sticks or glue them together. To make a h × w -sized frame, he needs two sticks whose lengths equal h and two sticks whose lengths equal w . Specifically, to make a square frame (when h = w ), he needs four sticks of the same length. Now Nicholas wants to make from the sticks that he has as many frames as possible; to be able to paint as many canvases as possible to fill the frames. Help him in this uneasy task. Note that it is not necessary to use all the sticks Nicholas has.的答案

欢迎关注区块链毕设网-
专业区块链毕业设计成品源码,定制。

区块链NFT链游项目方科学家脚本开发培训

承接区块链项目定制开发

微信:btc9767

QQ :1330797917

TELEGRAM: BTCOK9

承接区块链项目定制开发


qklbishe.com区块链毕设代做网专注|以太坊fabric-计算机|java|毕业设计|代做平台-javagopython毕设 » Nicholas, a painter is going to paint several new canvases. Nicholas is sure that the canvases will turn out so great that each one will need framing and being hung on the wall. Frames are what Nicholas decided to begin with. Nicholas has n sticks whose lengths equal a 1, a 2, … a n . Nicholas does not want to break the sticks or glue them together. To make a h × w -sized frame, he needs two sticks whose lengths equal h and two sticks whose lengths equal w . Specifically, to make a square frame (when h = w ), he needs four sticks of the same length. Now Nicholas wants to make from the sticks that he has as many frames as possible; to be able to paint as many canvases as possible to fill the frames. Help him in this uneasy task. Note that it is not necessary to use all the sticks Nicholas has.

发表回复