codeforces #236 div2 简洁题解

时间:2021-04-02 09:10:20

A:A. Nuts

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard 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 kabv (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)
input
3 10 3 3
output
2
input
3 10 1 3
output
3
input
100 100 1 1000
output
1
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[]; //盒子能放的个数
int main()
{
    int k,a,b,v;
    cin>>k>>a>>b>>v;
    int ans=;
    for (int i=;i<=;i++)
         aa[i]=v;               初始每个盒子开始只有一个SECTION
    for (int i=;i<=;i++)
     {
         if (b==) break;
         if (b+>=k) {aa[i]+=v*(k-);b-=(k-);}  有B则先用
         else
         {
             aa[i]+=b*v;
             break;
         }
     }
    int tem=,ll;
    for (int i=;i<=;i++)
    {
        tem+=aa[i];
        if (tem>=a) {ll=i;break;}
    }
    cout<<ll<<endl;
    return ;

}

B:题意很简单,构造等差数列,求改变的数的个数最小。。

从A[1]暴力枚举就可,不知为何我从A[N]枚举就挂,白WA5次 #include<iostream>

#include<algorithm>
#include<math.h>
using namespace std;
int a[],n,k;
int main()
{
    cin>>n>>k;
    for (int i=;i<=n;i++)
    cin>>a[i];
    int ans=;
    int kk;
    for (int i=;i<=;i++)
    {
        int o=;
        int tem=i;
        for (int j=;j<=n;j++)
        {
            if (a[j]!=tem)
            o++;
            tem+=k;
        }
        if (o<ans) {ans=o;kk=i;}
    }     cout<<ans<<endl;
    if (ans==) return ;
    for (int i=;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 ;
} 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[][];
int main()
{
  int t;
  cin>>t;
  while (t--)
  {
      int m=*n+p;
      memset(mp,,sizeof(mp));
      cin>>n>>p;
      for (int i=;i<n;i++)
        mp[i][i+]=;
        m=*n+p;
        m=m-(n-);
            for (int i=;i<n;i++)
            {
             if (m==) break;
             for (int j=;j+i<=n;j++)
             {
                mp[j][j+i]=;
                m--;
                if (m==) break;
              }
            }
    for (int i=;i<=n;i++)
        for (int j=;j<=n;j++)
        if (mp[i][j])
        cout<<i<<" "<<j<<endl;
  }
    return ;}还有不得不吐槽自己的码代码能力,太坑了