今日 日常训练三题 2019.4.9 暴力专题

time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Gennady is one of the best child dentists in Berland. Today n children got an appointment with him, they lined up in front of his office.

All children love to cry loudly at the reception at the dentist. We enumerate the children with integers from 1 to n in the order they go in the line. Every child is associated with the value of his cofidence pi. The children take turns one after another to come into the office; each time the child that is the first in the line goes to the doctor.

While Gennady treats the teeth of the i-th child, the child is crying with the volume of vi. At that the confidence of the first child in the line is reduced by the amount of vi, the second one — by value vi - 1, and so on. The children in the queue after the vi-th child almost do not hear the crying, so their confidence remains unchanged.

If at any point in time the confidence of the j-th child is less than zero, he begins to cry with the volume of dj and leaves the line, running towards the exit, without going to the doctor's office. At this the confidence of all the children after the j-th one in the line is reduced by the amount of dj.

All these events occur immediately one after the other in some order. Some cries may lead to other cries, causing a chain reaction. Once in the hallway it is quiet, the child, who is first in the line, goes into the doctor's office.

Help Gennady the Dentist to determine the numbers of kids, whose teeth he will cure. Print their numbers in the chronological order.

Input

The first line of the input contains a positive integer n (1 ≤ n ≤ 4000) — the number of kids in the line.

Next n lines contain three integers each vi, di, pi (1 ≤ vi, di, pi ≤ 106) — the volume of the cry in the doctor's office, the volume of the cry in the hall and the confidence of the i-th child.

Output

In the first line print number k — the number of children whose teeth Gennady will cure.

In the second line print k integers — the numbers of the children who will make it to the end of the line in the increasing order.

Examples
input
Copy
5
4 2 2
4 1 2
5 2 4
3 3 5
5 1 2
output
Copy
2
1 3
input
Copy
5
4 5 1
5 3 9
4 1 2
2 1 8
4 1 9
output
Copy
4
1 2 4 5
Note

In the first example, Gennady first treats the teeth of the first child who will cry with volume 4. The confidences of the remaining children will get equal to  - 2, 1, 3, 1, respectively. Thus, the second child also cries at the volume of 1 and run to the exit. The confidence of the remaining children will be equal to 0, 2, 0. Then the third child will go to the office, and cry with volume 5. The other children won't bear this, and with a loud cry they will run to the exit.

In the second sample, first the first child goes into the office, he will cry with volume 4. The confidence of the remaining children will be equal to 5,  - 1, 6, 8. Thus, the third child will cry with the volume of 1 and run to the exit. The confidence of the remaining children will be equal to 5, 5, 7. After that, the second child goes to the office and cry with the volume of 5. The confidences of the remaining children will be equal to 0, 3. Then the fourth child will go into the office and cry with the volume of 2. Because of this the confidence of the fifth child will be 1, and he will go into the office last.

 

 

这个是一个简单的模拟题,不过你需要认真读题,不然就会想我这样WA二十几发

这个题目有一个点要注意,就是如果有一个人跑掉,那就要马上处理跑掉的人对后面的影响,不然之后前面的人哭对后面的影响就会有问题。

然后就是模拟一下就好了

 

#include <iostream>
#include <algorithm>
#include <queue>
#include <map>
#include <cstring>
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
const int maxn = 5e3 + 10;
bool vis[maxn];
struct node
{
    ll v, d, p;
}exa[maxn];

int main()
{
    ll n, ans = 0;
    cin >> n;
    memset(vis, 0, sizeof(vis));
    for (int i = 1; i <= n; i++)
    {
        cin >> exa[i].v >> exa[i].d >> exa[i].p;
    }
    for (int i = 1; i <= n; i++)
    {
        if (exa[i].p < 0) continue;
        int sum = 0;
        int cnt = i;
        int v = exa[i].v;
        while(v&&cnt<=n)
        {
            cnt++;
            if (exa[cnt].p < 0) continue;
            exa[cnt].p -= v;
            v--;
        }
        for(int j=i+1;j<=n;j++)
        {
            if (exa[j].p >= 0)
            {
                exa[j].p -= sum;
                if(exa[j].p<0&&!vis[j])
                {
                    sum += exa[j].d;
                    vis[j] = 1;
                }
            }
            else if (vis[j] == 0)
            {
                sum += exa[j].d;
                vis[j] = 1;
            }
        }
        //printf("%lld %d i=%d\n", exa[i].p, sum, i);
    }
    for (int i = 1; i <= n; i++)
    {
        if (exa[i].p >= 0) ans++;
    }
    printf("%lld\n", ans);
    for (int i = 1; i <= n; i++)
    {
        if (exa[i].p >= 0) printf("%d ", i);
    }
    return 0;
}
/*5
4 2 2
4 1 2
5 2 4
3 3 5
5 1 2
*/

 

 

time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

As you know, majority of students and teachers of Summer Informatics School live in Berland for the most part of the year. Since corruption there is quite widespread, the following story is not uncommon.

Elections are coming. You know the number of voters and the number of parties — nn and mm respectively. For each voter you know the party he is going to vote for. However, he can easily change his vote given a certain amount of money. In particular, if you give ii-th voter cicibytecoins you can ask him to vote for any other party you choose.

The United Party of Berland has decided to perform a statistical study — you need to calculate the minimum number of bytecoins the Party needs to spend to ensure its victory. In order for a party to win the elections, it needs to receive strictly more votes than any other party.

Input

The first line of input contains two integers nn and mm (1n,m30001≤n,m≤3000) — the number of voters and the number of parties respectively.

Each of the following nn lines contains two integers pipi and cici (1pim1≤pi≤m, 1ci1091≤ci≤109) — the index of this voter's preferred party and the number of bytecoins needed for him to reconsider his decision.

The United Party of Berland has the index 11.

Output

Print a single number — the minimum number of bytecoins needed for The United Party of Berland to win the elections.

Examples
input
Copy
1 2
1 100
output
Copy
0
input
Copy
5 5
2 100
3 200
4 300
5 400
5 900
output
Copy
500
input
Copy
5 5
2 100
3 200
4 300
5 800
5 900
output
Copy
600
Note

In the first sample, The United Party wins the elections even without buying extra votes.

In the second sample, The United Party can buy the votes of the first and the fourth voter. This way The Party gets two votes, while parties 33, 44 and 55 get one vote and party number 22 gets no votes.

In the third sample, The United Party can buy the votes of the first three voters and win, getting three votes against two votes of the fifth party.

 

 

这个是一个特别恶心的贪心,不会写。

然后就没有用贪心写了,看了一个题解,写的简单易懂。

就是枚举成功需要的票数。

就是先对这个进行从大到小的排序,然后从前往后查询,如果有党的票数大于1号的票,那就行贿这个党派的这个人。

然后之后,如果得到的票数(行贿有竞争的党派)小于这个枚举的状态,那就从后往前去行贿就可以了。

然后对枚举的每一个状态取min

 

 

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <iostream>
#include <algorithm>
#include <vector>
#define inf 0x3f3f3f3f3f3f3f3f
using namespace std;
typedef long long ll;
const int maxn = 3e3 + 100;
struct node
{
    int id, mon;
}exa[maxn];
bool cmp(node a,node b)
{
    return a.mon > b.mon;
}
int vis[maxn], vit[maxn];

int main()
{
    int n, m;
    ll ans = inf, s = 0;
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
    {
        scanf("%d%d", &exa[i].id, &exa[i].mon);
        if (exa[i].id == 1) s++;
    }
    sort(exa + 1, exa + 1 + n,cmp);
    for(int i=s;i<=(n+1)/2;i++)
    {
        //printf("i=%d\n", i);
        memset(vis, 0, sizeof(vis));
        memset(vit, 0, sizeof(vit));
        ll sum = 0,num=s;
        for(int j=1;j<=n;j++)
        {
            node e = exa[j];
            vis[e.id]++;
            if(vis[e.id]>i-1&&e.id!=1)
            {
                vit[j] = 1;
                vis[e.id]--;
                num++;
                sum += e.mon;
                //printf("j=%d  sum=%d %d\n", j, sum,e.mon);
            }
        }
        for(int j=n;j>=1&&num<i;j--)
        {
            if(!vit[j]&&exa[j].id!=1)
            {
                num++;
                sum += exa[j].mon;
            }
        }
        if(num>=i)
        {
            ans = min(ans, sum);
        }
    }
    if (ans >= inf) printf("0\n");
    else printf("%lld\n", ans);
    return 0;
}
/*5 5
2 100
3 200
4 300
5 800
5 900
*/

 

 

 

time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Vitaly is a very weird man. He's got two favorite digits a and b. Vitaly calls a positive integer good, if the decimal representation of this integer only contains digits a and b. Vitaly calls a good number excellent, if the sum of its digits is a good number.

For example, let's say that Vitaly's favourite digits are 1 and 3, then number 12 isn't good and numbers 13 or 311 are. Also, number 111 is excellent and number 11 isn't.

Now Vitaly is wondering, how many excellent numbers of length exactly n are there. As this number can be rather large, he asks you to count the remainder after dividing it by 1000000007 (109 + 7).

A number's length is the number of digits in its decimal representation without leading zeroes.

Input

The first line contains three integers: abn (1 ≤ a < b ≤ 9, 1 ≤ n ≤ 106).

Output

Print a single integer — the answer to the problem modulo 1000000007 (109 + 7).

Examples
input
Copy
1 3 3
output
Copy
1
input
Copy
2 3 10
output
Copy
165




这个题目比较简单,居然有1800的分数,让我有点校震惊,首先你要发现放到n个位置之和为n*a~n*b(a<b),所以接下来你只要枚举就可以了,
先要求组合数,然后就是要线性递推求出逆元,然后就可以成功的求出组合数,之后就很简单了。
看代码

 

 

 

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <iostream>
#include <algorithm>
#include <vector>
#define inf 0x3f3f3f3f3f3f3f3f
using namespace std;
typedef long long ll;
const int maxn = 1e6 + 100;
const int mod = 1e9 + 7;
ll c[maxn];
ll inv[maxn];
int a, b, n;

int check(int x)
{
    while(x)
    {
        int p= x%10;
        if (p != a && p != b) return 0;
        x /= 10;
    }
    return 1;
}

int main()
{
    cin >> a >> b >> n;
    if (a > b) swap(a, b);
    ll suma = a * n;
    ll sumb = b * n;
    ll ans = 0;
    inv[1] = 1;
    for (int i = 2; i <= n; i++) inv[i] = (mod - mod / i) * 1ll * inv[mod%i] % mod;
    c[0] = 1;
    for (int i = 1; i <= n; i++)
    {
        c[i] = ((c[i - 1]%mod) * (((n + 1 - i)%mod) *inv[i]%mod)%mod) %mod;
        //printf("c[%d]=%lld\n", i, c[i]);
    }
    int num = n;
    for(ll i=suma;i<=sumb;)
    {
        if(check(i))
        {
            ans += c[num];
            ans %= mod;
        }
        i -= a;
        i += b;
        num--;
    }
    printf("%lld\n", ans);
    return 0;
}
/*
 6 8 14215
602000920
651581472
*/

 

 

 

 

posted @ 2019-04-08 22:25  EchoZQN  阅读(124)  评论(0编辑  收藏  举报