Hello 2018

这场还是tourist出题,我当时大晚上做完1题滚粗了

A. Modular Exponentiation
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

The following problem is well-known: given integers n and m, calculate

,

where 2n = 2·2·...·2 (n factors), and  denotes the remainder of division of x by y.

You are asked to solve the "reverse" problem. Given integers n and m, calculate

.
Input

The first line contains a single integer n (1 ≤ n ≤ 10^8).

The second line contains a single integer m (1 ≤ m ≤ 10^8).

Output

Output a single integer — the value of .

Examples
input
Copy
4
42
output
10
input
Copy
1
58
output
0
input
Copy
98765432
23456789
output
23456789
Note

In the first example, the remainder of division of 42 by 24 = 16 is equal to 10.

In the second example, 58 is divisible by 21 = 2 without remainder, and the answer is 0.

 

 A签到,但是也和数学有关啊

由于n m都很大,n小的话就是直接m%(2^n),n大的时候,需要余的数也很大了,大于m了,直接就是m了

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll n,m;
    cin>>n>>m;
    if(n>60)
        cout<<m<<"\n";
    else cout<<m%(1LL<<n)<<endl;
    return 0;
}
B. Christmas Spruce
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Consider a rooted tree. A rooted tree has one special vertex called the root. All edges are directed from the root. Vertex u is called a child of vertex v and vertex v is called a parent of vertex u if there exists a directed edge from v to u. A vertex is called a leaf if it doesn't have children and has a parent.

Let's call a rooted tree a spruce if its every non-leaf vertex has at least 3 leaf children. You are given a rooted tree, check whether it's a spruce.

The definition of a rooted tree can be found here.

Input

The first line contains one integer n — the number of vertices in the tree (3 ≤ n ≤ 1 000). Each of the next n - 1 lines contains one integer pi (1 ≤ i ≤ n - 1) — the index of the parent of the i + 1-th vertex (1 ≤ pi ≤ i).

Vertex 1 is the root. It's guaranteed that the root has at least 2 children.

Output

Print "Yes" if the tree is a spruce and "No" otherwise.

Examples
input
Copy
4
1
1
1
output
Yes
input
Copy
7
1
1
1
2
2
2
output
No
input
Copy
8
1
1
1
1
3
3
3
output
Yes
Note

The first example:

The second example:

It is not a spruce, because the non-leaf vertex 1 has only 2 leaf children.

The third example:

 

 

一个节点下面必须k叉的,直接统计就好了,但是has at least 3 leaf children,所以需要<=3,我没考虑这个啊

#include<bits/stdc++.h>
using namespace std;
const int N=100005;
int n,fa[N],use[N],f;
int main()
{
    scanf("%d",&n);
    for(int i=2; i<=n; i++)
        scanf("%d",&fa[i]),use[fa[i]]=1;
    for(int i=n; i>=1; i--)
        if(!use[i])use[fa[i]]++;
    for(int i=1; i<=n; i++)
        if(use[i]>0&&use[i]<4)f=1;
    if(!f)puts("Yes");
    else puts("No");
    return 0;
}

我直接dfs也要区分节点啊,所以+1好了,就和上面的一样正确了

#include<bits/stdc++.h>
using namespace std;
const int N=1005;
vector<int>V[N];
int F[N];
void dfs(int x)
{
     for(auto X:V[x])
     {
          if(V[X].size())dfs(X);
          else F[x]++;
     }
     F[x]++;
}
int main()
{
    int n,f=1;
    scanf("%d",&n);
    for(int u=2,v;u<=n;u++)
        scanf("%d",&v),V[v].push_back(u);
    dfs(1);
    for(int i=1;i<=n&&f;i++)
    if(F[i]&&F[i]<4)f=0;
    printf("%s",f?"YES":"NO");
    return 0;
}
C. Party Lemonade
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

A New Year party is not a New Year party without lemonade! As usual, you are expecting a lot of guests, and buying lemonade has already become a pleasant necessity.

Your favorite store sells lemonade in bottles of n different volumes at different costs. A single bottle of type i has volume 2i - 1 liters and costs ci roubles. The number of bottles of each type in the store can be considered infinite.

You want to buy at least L liters of lemonade. How many roubles do you have to spend?

Input

The first line contains two integers n and L (1 ≤ n ≤ 30; 1 ≤ L ≤ 109) — the number of types of bottles in the store and the required amount of lemonade in liters, respectively.

The second line contains n integers c1, c2, ..., cn (1 ≤ ci ≤ 109) — the costs of bottles of different types.

Output

Output a single integer — the smallest number of roubles you have to pay in order to buy at least L liters of lemonade.

Examples
input
Copy
4 12
20 30 70 90
output
150
input
Copy
4 3
10000 1000 100 10
output
10
input
Copy
4 3
10 100 1000 10000
output
30
input
Copy
5 787787787
123456789 234567890 345678901 456789012 987654321
output
44981600785557577
Note

In the first example you should buy one 8-liter bottle for 90 roubles and two 2-liter bottles for 30 roubles each. In total you'll get 12 liters of lemonade for just 150 roubles.

In the second example, even though you need only 3 liters, it's cheaper to buy a single 8-liter bottle for 10 roubles.

In the third example it's best to buy three 1-liter bottles for 10 roubles each, getting three liters for 30 roubles.

模拟题,看样例猜题意看题目一条龙

#include <iostream>
using namespace std;
long long n,l,d,a[35],i,c,s=1e18;
int main()
{
    cin>>n>>l>>a[0];
    for(int i=1; i<n; i++)
        cin>>a[i],a[i]=min(a[i-1]*2,a[i]);
    for(int i=n-1; i>=0; i--)
    {
        d=(1<<i);
        c+=a[i]*(l/d);
        l%=d;
        s=min(s,c+(l!=0)*a[i]);
    }
    cout<<s;
}
D. Too Easy Problems
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

You are preparing for an exam on scheduling theory. The exam will last for exactly T milliseconds and will consist of n problems. You can either solve problem i in exactly ti milliseconds or ignore it and spend no time. You don't need time to rest after solving a problem, either.

Unfortunately, your teacher considers some of the problems too easy for you. Thus, he assigned an integer ai to every problem i meaning that the problem i can bring you a point to the final score only in case you have solved no more than ai problems overall (including problem i).

Formally, suppose you solve problems p1, p2, ..., pk during the exam. Then, your final score s will be equal to the number of values of jbetween 1 and k such that k ≤ apj.

You have guessed that the real first problem of the exam is already in front of you. Therefore, you want to choose a set of problems to solve during the exam maximizing your final score in advance. Don't forget that the exam is limited in time, and you must have enough time to solve all chosen problems. If there exist different sets of problems leading to the maximum final score, any of them will do.

Input

The first line contains two integers n and T (1 ≤ n ≤ 2·105; 1 ≤ T ≤ 109) — the number of problems in the exam and the length of the exam in milliseconds, respectively.

Each of the next n lines contains two integers ai and ti (1 ≤ ai ≤ n1 ≤ ti ≤ 104). The problems are numbered from 1 to n.

Output

In the first line, output a single integer s — your maximum possible final score.

In the second line, output a single integer k (0 ≤ k ≤ n) — the number of problems you should solve.

In the third line, output k distinct integers p1, p2, ..., pk (1 ≤ pi ≤ n) — the indexes of problems you should solve, in any order.

If there are several optimal sets of problems, you may output any of them.

Examples
input
Copy
5 300
3 100
4 150
4 80
2 90
2 300
output
2
3
3 1 4
input
Copy
2 100
1 787
2 788
output
0
0

input
Copy
2 100
2 42
2 58
output
2
2
1 2
Note

In the first example, you should solve problems 3, 1, and 4. In this case you'll spend 80 + 100 + 90 = 270 milliseconds, falling within the length of the exam, 300 milliseconds (and even leaving yourself 30 milliseconds to have a rest). Problems 3 and 1 will bring you a point each, while problem 4 won't. You'll score two points.

In the second example, the length of the exam is catastrophically not enough to solve even a single problem.

In the third example, you have just enough time to solve both problems in 42 + 58 = 100 milliseconds and hand your solutions to the teacher with a smile.

 

 特判题

我选择二分

#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
int T,n,l,r,tot,t;
struct TT
{
    int x,y,t;
} a[N];
int cmp(TT a,TT b)
{
    return a.x<b.x;
}
int main()
{
    scanf("%d%d",&n,&T);
    for(int i=1; i<=n; i++)scanf("%d%d",&a[i].y,&a[i].x),a[i].t=i;
    sort(a+1,a+n+1,cmp);
    int l=0,r=n;
    while(l<r)
    {
        int mi=l+r+1>>1;
        tot=t=0;
        for(int i=1; i<=n; i++)
            if(a[i].y>=mi)
            {
                if(tot+a[i].x>T)break;
                else tot+=a[i].x,t++;
            }
        if(t>=mi)l=mi;
        else r=mi-1;
    }
    t=0;
    printf("%d\n%d\n",l,l);
    for(int i=1; i<=n&&t<l; i++)
        if(a[i].y>=l)
            printf("%d ",a[i].t),t++;
    return 0;
}

 

转载于:https://www.cnblogs.com/BobHuang/p/8481511.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值