日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

codeforces #236 div2 简洁题解

發布時間:2023/12/10 编程问答 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 codeforces #236 div2 简洁题解 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
A:A. Nutstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

You have?a?nuts and lots of boxes. The boxes have a wonderful feature: if you put?x?(x?≥?0)divisors (the spacial bars that can divide a box) to it, you get a box, divided into?x?+?1sections.

You are minimalist. Therefore, on the one hand, you are against dividing some box into more than?k?sections. On the other hand, you are against putting more than?v?nuts into some section of the box. What is the minimum number of boxes you have to use if you want to put all the nuts in boxes, and you have?b?divisors?

Please note that you need to minimize the number of used boxes, not sections. You do not have to minimize the number of used divisors.

Input

The first line contains four space-separated integers?k,?a,?b,?v?(2?≤?k?≤?1000;?1?≤?a,?b,?v?≤?1000) — the maximum number of sections in the box, the number of nuts, the number of divisors and the capacity of each section of the box.

Output

Print a single integer — the answer to the problem.

Sample test(s)input3 10 3 3
output2
input3 10 1 3
output3
input100 100 1 1000
output1
Note

In the first sample you can act like this:

  • Put two divisors to the first box. Now the first box has three sections and we can put three nuts into each section. Overall, the first box will have nine nuts.
  • Do not put any divisors into the second box. Thus, the second box has one section for the last nut.

In the end we've put all the ten nuts into boxes.

The second sample is different as we have exactly one divisor and we put it to the first box. The next two boxes will have one section each.

?

?花了半個多小時去理清數據的關系,開始感覺無從下手。。。我的方法是:制造相應的盒子,能放多少就盡量放到前面的盒子里面,最后統計一下就可以

#include<iostream>
#include<algorithm>
#include<math.h>
using?namespace?std;
int?aa[2000];?//盒子能放的個數
int?main()
{
????int?k,a,b,v;
????cin>>k>>a>>b>>v;
????int?ans=0;
????for?(int?i=1;i<=2000;i++)
?????????aa[i]=v;???????????????初始每個盒子開始只有一個SECTION
????for?(int?i=1;i<=2000;i++)
?????{
?????????if?(b==0)?break;
?????????if?(b+1>=k)?{aa[i]+=v*(k-1);b-=(k-1);}??有B則先用
?????????else
?????????{
?????????????aa[i]+=b*v;
?????????????break;
?????????}
?????}
????int?tem=0,ll;
????for?(int?i=1;i<=1000;i++)
????{
????????tem+=aa[i];
????????if?(tem>=a)?{ll=i;break;}
????}
????cout<<ll<<endl;
????return?0;

}?

?

B:題意很簡單,構造等差數列,求改變的數的個數最小。。

從A[1]暴力枚舉就可,不知為何我從A[N]枚舉就掛,白WA5次?#include<iostream>

#include<algorithm>
#include<math.h>
using?namespace?std;
int?a[2000],n,k;
int?main()
{
????cin>>n>>k;
????for?(int?i=1;i<=n;i++)
????cin>>a[i];
????int?ans=99999;
????int?kk;
????for?(int?i=1;i<=1000;i++)
????{
????????int?o=0;
????????int?tem=i;
????????for?(int?j=1;j<=n;j++)
????????{
????????????if?(a[j]!=tem)
????????????o++;
????????????tem+=k;
????????}
????????if?(o<ans)?{ans=o;kk=i;}
????}

????cout<<ans<<endl;
????if?(ans==0)?return?0;
????for?(int?i=1;i<=n;i++)
????{
????????if?(a[i]>kk)?{cout<<"-?"<<i<<"?"<<a[i]-kk<<endl;}
????????else?if?(a[i]<kk)?{cout<<"+?"<<i<<"?"<<kk-a[i]<<endl;}
????????kk+=k;
????}
????return?0;
}

?

C題,我是瞎搞,我的理解是使點連接的邊相對稀少,先這樣加邊:1-->2,2-->3,3-->4,n-1-->n;先見N-1條邊,

然后:1-->3,2-->4,3-->5,依次;

然后是:1--4,2-->5,....感覺這樣相對不密集。。#include<iostream>

#include<algorithm>
#include<math.h>
#include<string.h>
using?namespace?std;
int?n,p;
int?mp[1000][1000];
int?main()
{
??int?t;
??cin>>t;
??while?(t--)
??{
??????int?m=2*n+p;
??????memset(mp,0,sizeof(mp));
??????cin>>n>>p;
??????for?(int?i=1;i<n;i++)
????????mp[i][i+1]=1;
????????m=2*n+p;
????????m=m-(n-1);
????????????for?(int?i=2;i<n;i++)
????????????{
?????????????if?(m==0)?break;
?????????????for?(int?j=1;j+i<=n;j++)
?????????????{
????????????????mp[j][j+i]=1;
????????????????m--;
????????????????if?(m==0)?break;
??????????????}
????????????}
????for?(int?i=1;i<=n;i++)
????????for?(int?j=1;j<=n;j++)
????????if?(mp[i][j])
????????cout<<i<<"?"<<j<<endl;
??}
????return?0;

}

還有不得不吐槽自己的碼代碼能力,太坑了?

轉載于:https://www.cnblogs.com/forgot93/p/3604401.html

總結

以上是生活随笔為你收集整理的codeforces #236 div2 简洁题解的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。