zoj4047

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 A​1​​,A​2​​,...,A​n​​ (A​i​​∈ {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 (1≤i≤n−k+1) such that A​i​​=A​i+1​​=A​i+2​​=...=A​i+k−1​​= 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 (n−m) 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 (1≤T≤100), indicating the number of test cases. For each test case:

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

Output

For each test case output one line containing two integers s​max​​ and s​min​​, 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表示(完美,不完美)的总个数,m表示完美的个数。求最多的连续完美数,和最少的不完美数。

解析:考虑用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;
}

zoj4049

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 v 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 v 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 v 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 v 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 (1≤n≤10​4​​), 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 (0≤v≤255), indicating the value added to the register;
  • Otherwise, two integers v and k follow (0≤v≤255, 1≤k≤n), 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 10​5​​.

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.

解析:题意自己理解吧  不多说。其实可以发现,要是其中的一个步骤出现了2次状态(就是这个步骤进行了256次后又有再一次出现)说明这个进程肯定是死循环的。

#include<cstdlib>
#include<cstdio>
#include<queue>
#include<cstring>
#include<cmath>
using namespace std;#define ee exp(1)
#define pi acos(-1)
#define MOD 1000000007
#define inf 0x3f3f3f3f
#define ll long long
#define ull unsigned long long
#define mem(a,b) memset(a,b,sizeof(a))
int gcd(int a,int b){return b?gcd(b,a%b):a;}char s[10];
int n,vv,r,k,flag;
struct node{char c;int v,k,cnt;
}q[10005];
int main()
{int T;scanf("%d",&T);while(T--){r=0;flag=1;scanf("%d",&n);for(int i=1; i<=n; i++){scanf("%s %d",s,&vv);if(s[0]!='a'){scanf("%d",&k);q[i].c=s[1];q[i].k=k;}else{q[i].c='a';q[i].k=0;}q[i].v=vv;q[i].cnt=0;}int i=1;while(true){if(q[i].c=='a')r=(q[i].v+r)%256,i++;else if(q[i].c=='e'){if(r==q[i].v)i=q[i].k,q[i].cnt++;else i++;}else if(q[i].c=='n'){if(r!=q[i].v)i=q[i].k,q[i].cnt++;else i++;}else if(q[i].c=='l'){if(r<q[i].v)i=q[i].k,q[i].cnt++;else i++;}else if(q[i].c=='g'){if(r>q[i].v)i=q[i].k,q[i].cnt++;else i++;}if(i>n)break;if(q[i].cnt>300){flag=0;break;}}if(flag||i==n+1)puts("Yes");else puts("No");}return 0;
}

zoj4054

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 (i−0.5) for all i∈[1,n], where i is an integer, stands a traffic light of type t​i​​ (t​i​​∈{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=0​∑​n−1​​​q=p+1​∑​n​​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 (1≤∣s∣≤10​5​​, ∣s∣=n, s​i​​∈{‘0’,‘1’} for all 1≤i≤∣s∣), indicating the types of the traffic lights. If s​i​​=‘0’, the traffic light at point (i−0.5) is of type 0 and is initially red; If s​i​​=‘1’, the traffic light at point (i−0.5) is of type 1 and is initially green.

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

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就炸了

我还没看懂他的代码

队友给各位老板的题解

s    1  0  1  1  0  0  1
0->n 1  2  3  5  6  8  9
以0为起点:1 2 3 5 6 8 9
以1为起点:   2 3 5 6 8 9
以2为起点:      1 3 4 6 7
以3为起点:         1 2 4 5
以4为起点:            2 4 5
以5为起点:               2 3
以6为起点:                  1
可以观察到若该位为1,该位值则减至1,后面的值也都要减少这位减少的值,若该位为0,该位值则减至2,后面的值也都要减少这位减少的值.
(即i到n的和-第i位与1或2的差值*区间长度)

#include<bits/stdc++.h>
using namespace std;#define e exp(1)
#define pi acos(-1)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define ll long long
#define ull unsigned long long
#define mem(a,b) memset(a,b,sizeof(a))
int gcd(int a,int b){return b?gcd(b,a%b):a;}ll sum[100005];
char s[100005];
int main()
{int T;scanf("%d",&T);while(T--){mem(sum,0);scanf("%s",s+1);s[0]='0';int n=strlen(s+1);for(int i=1; i<=n; i++)sum[i]=sum[i-1]+1+(s[i]==s[i-1]);for(int i=1; i<=n; i++)sum[i]+=sum[i-1];ll ans=0;for(int i=1; i<=n; i++){if(s[i]=='0')ans+=sum[n]-sum[i-1]-(sum[i]-sum[i-1]-2)*(n-i+1);else ans+=sum[n]-sum[i-1]-(sum[i]-sum[i-1]-1)*(n-i+1);}printf("%lld\n",ans);}return 0;
}

zoj4057

K XOR Clique

BaoBao has a sequence a​1​​,a​2​​,...,a​n​​. He would like to find a subset S of {1,2,...,n} such that ∀i,j∈S, a​i​​⊕a​j​​<min(a​i​​,a​j​​) 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 (1≤n≤10​5​​), indicating the length of the sequence.

The second line contains n integers: a​1​​,a​2​​,...,a​n​​ (1≤a​i​​≤10​9​​), indicating the sequence.

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

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

要异或值小于其中的数,说明最高位肯定要相同,说明直接找最多位相同的子集即可。

#include<bits/stdc++.h>
using namespace std;#define ee exp(1)
#define pi acos(-1)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define ll long long
#define ull unsigned long long
#define mem(a,b) memset(a,b,sizeof(a))
int gcd(int a,int b){return b?gcd(b,a%b):a;}int a[45];
int main()
{int T;scanf("%d",&T);while(T--){mem(a,0);int n;scanf("%d",&n);for(int i=0; i<n; i++){ll x;scanf("%lld",&x);int cnt=0;while(x){cnt++;x>>=1;}a[cnt]++;}int ans=0;for(int i=1; i<40; i++){if(a[i]>1)ans=max(ans,a[i]);}printf("%d\n",ans);}return 0;
}

The 2018 ACM-ICPC Asia Qingdao Regional Contest, Online相关推荐

  1. 2016 ACM / ICPC Asia dalian Regional Contest 题解(11 / 11)【每日亿题2021 / 2 / 17】

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 目录 A .(2017 ACM ICPC dalian H)To begin or not to be ...

  2. 2017 ACM ICPC Asia Shenyang Regional Contest 题解(10 / 13)【每日亿题2 / 16】

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 目录 A.(2017 ICPC shenyang I)Little Boxes B.(2017 ICP ...

  3. The 2018 ACM-ICPC Asia Qingdao Regional Contest

    The 2018 ACM-ICPC Asia Qingdao Regional Contest 青岛总体来说只会3题 C #include<bits/stdc++.h> using nam ...

  4. 2018 ICPC Asia Jakarta Regional Contest

    2018 ICPC Asia Jakarta Regional Contest 题号 题目 知识点 难度 A Edit Distance B Rotating Gear C Smart Thief D ...

  5. The 2019 ICPC Asia Shanghai Regional Contest

    The 2019 ICPC Asia Shanghai Regional Contest 题号 题目 知识点 A Mr. Panda and Dominoes B Prefix Code C Maze ...

  6. 【题目记录】——The 2021 ICPC Asia Jinan Regional Contest

    文章目录 C Optimal Strategy 组合数 H Game Coin K Search For Mafuyu 欧拉序列 题目集地址 The 2021 ICPC Asia Jinan Regi ...

  7. 2019-2020 ICPC Asia Xuzhou Regional Contest【徐州现场赛】

    题目: 209-2020 ICPC Asia Xuzhou Regional Onsite Contest E. Multiply 题意: 找到最大的 i 使得 z*x^i 是 y! 的因子 分析: ...

  8. Traveling on the Axis (The 2018 ACM-ICPC Asia Qingdao Regional Contest, Online)

    题目链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=4054 题意就是一个小孩走一段路,这条路上有n个红绿灯,并且告诉 ...

  9. 2018 ICPC Asia Jakarta Regional Contest J. Future Generation 状压dp

    传送门 文章目录 题意: 思路: 题意: 给你nnn个串,字符集是a−za-za−z,让你在每个串种选择一个子序列,保证对于i<j,si<sji<j,s_i<s_ji<j ...

最新文章

  1. 自动驾驶公司Momenta完成超2亿美元融资,估值超10亿美元
  2. 【AJAX】DWR使用总结
  3. httping 2.2.1 发布,测试 HTTP 连接的工具
  4. [2017-08-31]如何使用ruby同步markdown博文到博客园
  5. django 设置登录成功后的页面
  6. Apache Spark源码走读之22 -- 浅谈mllib中线性回归的算法实现
  7. mysql出错代码表
  8. 使用pienv安装python虚拟环境(学习记录)
  9. 齿轮的正负变位设计要点
  10. 基于arduino制作激光电子竖琴
  11. RunningCheese Firefox 71.0 正式版 [1225]
  12. LINUX上基于ASM的ORACLE11的安装
  13. 混合柯西变异和均匀分布的蝗虫优化算法-附代码
  14. 【费用流】洛谷1251 餐巾计划问题
  15. 美国纽约大学超级计算机中心,美国纽约最好的八所大学介绍
  16. 【收藏】林达华 概率模型与计算机视觉
  17. POI excel单元格中内容换行
  18. 如何制作校园平面图及路线导图
  19. 编程队伍队名_关于举办十四所第四届“国睿杯”青年软件技能编程大赛的通知...
  20. Python官网安装包下载慢

热门文章

  1. python--paramiko模块
  2. python同时兼容2和3的几个技巧
  3. Golang 入门笔记(二)上
  4. C++中的内联函数inline总结
  5. 二十万字C/C++、嵌入式软开面试题全集宝典四
  6. 【Python】保留小数点后两位精度
  7. 云炬创业政策学习笔记20210113
  8. 云炬随笔20161012
  9. git bash 操作文件及文件夹命令
  10. VTK修炼之道60:体绘制_体绘制管线图形渲染管线