HJ13547816754 2017-10-15 14:59
浏览 411

各位大佬,帮忙看一下哪里出差了(codeforces 839B)

Daenerys Targaryen has an army consisting of k groups of soldiers, the i-th group contains ai soldiers. She wants to bring her army to the other side of the sea to get the Iron Throne. She has recently bought an airplane to carry her army through the sea. The airplane has n rows, each of them has 8 seats. We call two seats neighbor, if they are in the same row and in seats {1, 2}, {3, 4}, {4, 5}, {5, 6} or {7, 8}.

A row in the airplane
Daenerys Targaryen wants to place her army in the plane so that there are no two soldiers from different groups sitting on neighboring seats.

Your task is to determine if there is a possible arranging of her army in the airplane such that the condition above is satisfied.
#include
#include
#include
#include
using namespace std;
int K[10000];
int main(void)
{

//freopen("input.txt","r",stdin);
int n,k;
cin>>n>>k;
int left4=n;
int left2=n*2;
int left1=0;
for(int i=0;i {
cin>>K[i];
}
for(int i=0;i {
if(K[i]>=4)
{
if(left4>=K[i]/4)
{
left4-=K[i]/4;
K[i]=K[i]%4;
}
else
{
K[i]=K[i]-left4*4;
left4=0;
left2-=K[i]/4*2;
K[i]=K[i]%4;
}
}
}
for(int i=0;i {
if(K[i]==3)
{
if(left4>0)
{
left4--;
}
else
{
left2-=2;
}
}
}
for(int i=0;i {
if(K[i]==2)
{
if(left4>0)
{
left4--;
left1++;
}
else
{
left2--;
}
}
}
for(int i=0;i {
if(K[i]==1)
{
if(left4>0)
{
left4--;
left2++;
}
else if(left1>0)
{
left1--;
}
else
{
left2--;
}
}
}
if(left2<0)
{
cout<<"NO";
}
else
{
cout<<"YES";
}

return 0;

}

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥30 这是哪个作者做的宝宝起名网站
    • ¥60 版本过低apk如何修改可以兼容新的安卓系统
    • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
    • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
    • ¥50 有数据,怎么用matlab求全要素生产率
    • ¥15 TI的insta-spin例程
    • ¥15 完成下列问题完成下列问题
    • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
    • ¥15 YoloV5 第三方库的版本对照问题
    • ¥15 请完成下列相关问题!