The 2018 ACM-ICPC Asia Qingdao Regional Contest, Online

A Live Love

DreamGrid is playing the music game Live Love. He has just finished a song consisting of n notes and got a result sequence A1​​,A2​​,...,An​​ (Ai​​∈ {PERFECT, NON-PERFECT}). The score of the song is equal to the max-combo of the result sequence, which is defined as the maximum number of continuous PERFECTs in the sequence.

Formally speaking, max-combo(A)=max { k | k is an integer and there exists an integer i (1ink+1) such that Ai​​=Ai+1​​=Ai+2​​=...=Ai+k1​​= PERFECT }. For completeness, we define max()=0.

As DreamGrid is forgetful, he forgets the result sequence immediately after finishing the song. All he knows is the sequence length n and the total number of PERFECTs in the sequence, indicated by m. Any possible score s he may get must satisfy that there exists a sequence A​​ of length ncontaining exactly m PERFECTs and (nm) NON-PERFECTs and max-combo(A​​)=s. Now he needs your help to find the maximum and minimum s among all possible scores.

Input

There are multiple test cases. The first line of the input contains an integer T (1T100), indicating the number of test cases. For each test case:

The only line contains two integers n and m (1n103​​, 0m103​​, mn), indicating the sequence length and the number of PERFECTs DreamGrid gets.

Output

For each test case output one line containing two integers smax​​ and smin​​, indicating the maximum and minimum possible score.

Sample Input
5
5 4
100 50
252 52
3 0
10 10
Sample Output
4 2
50 1
52 1
0 0
10 10
Hint

Let's indicate a PERFECT as P and a NON-PERFECT as N.

For the first sample test case, the sequence (P,P,P,P,N)leads to the maximum score and the sequence (P,P,N,P,P) leads to the minimum score.

考虑用N去分隔P,就可以得到第二个答案

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int T,n,m;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d%d",&n,&m);
        n-=m;
        printf("%d %d\n",m,(m+n)/(n+1));
    }
    return 0;
}
C Halting Problem

In computability theory, the halting problem is the problem of determining, from a description of an arbitrary computer program, whether the program will finish running (i.e., halt) or continue to run forever.

Alan Turing proved in 1936 that a general algorithm to solve the halting problem cannot exist, but DreamGrid, our beloved algorithm scientist, declares that he has just found a solution to the halting problem in a specific programming language -- the Dream Language!

Dream Language is a programming language consists of only 5 types of instructions. All these instructions will read from or write to a 8-bit register r, whose value is initially set to 0. We now present the 5 types of instructions in the following table. Note that we denote the current instruction as the i-th instruction.

Instruction Description
add v Add v to the register r. As r is a 8-bit register, this instruction actually calculates (r+v)mod256 and stores the result into r, i.e. r(r+v)mod256. After that, go on to the (i+1)-th instruction.
beq k If the value of r is equal to v, jump to the k-th instruction, otherwise go on to the (i+1)-th instruction.
bne k If the value of r isn't equal to v, jump to the k-th instruction, otherwise go on to the (i+1)-th instruction.
blt k If the value of r is strictly smaller than v, jump to the k-th instruction, otherwise go on to the (i+1)-th instruction.
bgt k If the value of r is strictly larger than v, jump to the k-th instruction, otherwise go on to the (i+1)-th instruction.

A Dream Language program consisting of n instructions will always start executing from the 1st instruction, and will only halt (that is to say, stop executing) when the program tries to go on to the (n+1)-th instruction.

As DreamGrid's assistant, in order to help him win the Turing Award, you are asked to write a program to determine whether a given Dream Language program will eventually halt or not.

Input

There are multiple test cases. The first line of the input is an integer T, indicating the number of test cases. For each test case:

The first line contains an integer n (1n104​​), indicating the number of instructions in the following Dream Language program.

For the following n lines, the i-th line first contains a string s(s{“add”,“beq”,“bne”,“blt”,“bgt”}), indicating the type of the i-th instruction of the program.

  • If s equals to "add", an integer v follows (0v255), indicating the value added to the register;
  • Otherwise, two integers v and k follow (0v255, 1kn), indicating the condition value and the destination of the jump.

It's guaranteed that the sum of n of all test cases will not exceed 105​​.

Output

For each test case output one line. If the program will eventually halt, output "Yes" (without quotes); If the program will continue to run forever, output "No" (without quotes).

Sample Input
4
2
add 1
blt 5 1
3
add 252
add 1
bgt 252 2
2
add 2
bne 7 1
3
add 1
bne 252 1
beq 252 1
Sample Output
Yes
Yes
No
No
Hint

For the second sample test case, note that r is a 8-bit register, so after four "add 1" instructions the value of r will change from 252 to 0, and the program will halt.

For the third sample test case, it's easy to discover that the value of r will always be even, so it's impossible for the value of r to be equal to 7, and the program will run forever.

把他所有操作都模拟下来,然后hash记录一下

队友记录次数要不超时,要不wa,还是我有经验啊

#include<bits/stdc++.h>
using namespace std;

const int maxn=10005;
const int mod=256;
int v[maxn],k[maxn];
char s[maxn][5];
bool has[maxn][256];
int main()
{
    int t,n;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        for(int i=1;i<=n;i++)
        {
            scanf("%s",s[i]);
            if(s[i][0]=='a')
                scanf("%d",&v[i]);
            else
                scanf("%d%d",&v[i],&k[i]);
        }
        int now=1,r=0;
        memset(has,false,sizeof has);
        while(now<=n)
        {
            if(has[now][r]==true)break;
            has[now][r]=true;
            if(s[now][0]=='a')
                r=(r+v[now])%mod,now++;
            else if(s[now][0]=='b'&&s[now][1]=='e')
                if(r==v[now])now=k[now];
                else now++;
            else if(s[now][0]=='b'&&s[now][1]=='n')
                if(r!=v[now])now=k[now];
                else now++;
            else if(s[now][0]=='b'&&s[now][1]=='l')
                if(r<v[now])now=k[now];
                else now++;
            else if(s[now][0]=='b'&&s[now][1]=='g')
                if(r>v[now])now=k[now];
                else now++;
            //printf("now=%d r=%d\n",now,r);
        }
        printf("%s\n",now==n+1?"Yes":"No");
    }
    return 0;
}
H Traveling on the Axis

BaoBao is taking a walk in the interval [0,n] on the number axis, but he is not free to move, as at every point (i0.5) for all i[1,n], where i is an integer, stands a traffic light of type ti​​ (ti​​{0,1}).

BaoBao decides to begin his walk from point p and end his walk at point q (both p and q are integers, and p<q). During each unit of time, the following events will happen in order:

  1. Let's say BaoBao is currently at point x, he will then check the traffic light at point (x+0.5). If the traffic light is green, BaoBao will move to point (x+1); If the traffic light is red, BaoBao will remain at point x.
  2. All the traffic lights change their colors. If a traffic light is currently red, it will change to green; If a traffic light is currently green, it will change to red.

A traffic light of type 0 is initially red, and a traffic light of type 1 is initially green.

Denote t(p,q) as the total units of time BaoBao needs to move from point p to point q. For some reason, BaoBao wants you to help him calculate

p=0n1​​q=p+1n​​t(p,q)

where both p and q are integers. Can you help him?

Input

There are multiple test cases. The first line of the input contains an integer T, indicating the number of test cases. For each test case:

The first and only line contains a string s (1s105​​, s=n, si​​{‘0’,‘1’} for all 1is∣), indicating the types of the traffic lights. If si​​=‘0’, the traffic light at point (i0.5) is of type 0 and is initially red; If si​​=‘1’, the traffic light at point (i0.5) is of type 1 and is initially green.

It's guaranteed that the sum of s∣ of all test cases will not exceed 106​​.

Output

For each test case output one line containing one integer, indicating the answer.

Sample Input
3
101
011
11010
Sample Output
12
15
43
Hint

For the first sample test case, it's easy to calculate that t(0,1)=1, t(0,2)=2, t(0,3)=3, t(1,2)=2, t(1,3)=3and t(2,3)=1, so the answer is 1+2+3+2+3+1=12.

For the second sample test case, it's easy to calculate that t(0,1)=2, t(0,2)=3, t(0,3)=5, t(1,2)=1, t(1,3)=3and t(2,3)=1, so the answer is 2+3+5+1+3+1=15.

这个队友一个前缀和就过了,可惜一个爆int就炸了
我还没看懂他的代码
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
char s[100005];
ll pre[100005];
int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        memset(pre,0,sizeof pre);
        scanf("%s",s+1);
        s[0]='0';
        int l=strlen(s+1);
        for(int i=1;i<=l;i++)
            pre[i]=pre[i-1]+1+(s[i]==s[i-1]);
        for(int i=1;i<=l;i++)
            pre[i]+=pre[i-1];
        ll ans=0;
        for(int i=1;i<=l;i++)
        {
            if(s[i]=='0') ans+=pre[l]-pre[i-1]-(pre[i]-pre[i-1]-2)*(l-i+1);
            else ans+=pre[l]-pre[i-1]-(pre[i]-pre[i-1]-1)*(l-i+1);
        }
        printf("%lld\n",ans);
    }
    return 0;
}
K XOR Clique

BaoBao has a sequence a1​​,a2​​,...,an​​. He would like to find a subset S of {1,2,...,n} such that i,jS, ai​​aj​​<min(ai​​,aj​​) and S∣ is maximum, where ⊕ means bitwise exclusive or.

Input

There are multiple test cases. The first line of input contains an integer T, indicating the number of test cases. For each test case:

The first line contains an integer n (1n105​​), indicating the length of the sequence.

The second line contains n integers: a1​​,a2​​,...,an​​ (1ai​​109​​), indicating the sequence.

It is guaranteed that the sum of n in all cases does not exceed 105​​.

Output

For each test case, output an integer denoting the maximum size of S.

Sample Input
3
3
1 2 3
3
1 1 1
5
1 2323 534 534 5
Sample Output
2
3
2


因为要消除其他位的1,而且是小于的最小,所以肯定是高位啊

所以只有这一个题是我做的喽,实力划水

#include<stdio.h>
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lson l,(l+r)/2,rt<<1
#define rson (l+r)/2+1,r,rt<<1|1
#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define pb push_back
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define pll pair<long long,long long>
#define pii pair<int,int>
#define pq priority_queue
const int N=1e5+5,MD=1e9+7,INF=0x3f3f3f3f;
const ll LL_INF=0x3f3f3f3f3f3f3f3f;
const double eps=1e-9,e=exp(1),PI=acos(-1.);
int a[32],b[32];
int main()
{
    ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    int T;
    cin>>T;
    while(T--)
    {
        for(int j=0; j<32; j++)b[j]=0;
        int n;
        cin>>n;
        for(int i=0,x; i<n; i++)
        {
            cin>>x;
            int l=0;
            while(x)l++,x>>=1;
            b[l-1]++;
        }
        int ma=0;
        for(int i=0;i<32;i++)ma=max(ma,b[i]);
        cout<<ma<<"\n";
    }
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/BobHuang/p/9660659.html