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去分隔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+));
}
return ;
}
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.

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

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

#include<bits/stdc++.h>
using namespace std; const int maxn=;
const int mod=;
int v[maxn],k[maxn];
char s[maxn][];
bool has[maxn][];
int main()
{
int t,n;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(int i=;i<=n;i++)
{
scanf("%s",s[i]);
if(s[i][]=='a')
scanf("%d",&v[i]);
else
scanf("%d%d",&v[i],&k[i]);
}
int now=,r=;
memset(has,false,sizeof has);
while(now<=n)
{
if(has[now][r]==true)break;
has[now][r]=true;
if(s[now][]=='a')
r=(r+v[now])%mod,now++;
else if(s[now][]=='b'&&s[now][]=='e')
if(r==v[now])now=k[now];
else now++;
else if(s[now][]=='b'&&s[now][]=='n')
if(r!=v[now])now=k[now];
else now++;
else if(s[now][]=='b'&&s[now][]=='l')
if(r<v[now])now=k[now];
else now++;
else if(s[now][]=='b'&&s[now][]=='g')
if(r>v[now])now=k[now];
else now++;
//printf("now=%d r=%d\n",now,r);
}
printf("%s\n",now==n+?"Yes":"No");
}
return ;
}
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;
typedef long long ll;
char s[];
ll pre[];
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
memset(pre,,sizeof pre);
scanf("%s",s+);
s[]='';
int l=strlen(s+);
for(int i=;i<=l;i++)
pre[i]=pre[i-]++(s[i]==s[i-]);
for(int i=;i<=l;i++)
pre[i]+=pre[i-];
ll ans=;
for(int i=;i<=l;i++)
{
if(s[i]=='') ans+=pre[l]-pre[i-]-(pre[i]-pre[i-]-)*(l-i+);
else ans+=pre[l]-pre[i-]-(pre[i]-pre[i-]-)*(l-i+);
}
printf("%lld\n",ans);
}
return ;
}
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

因为要消除其他位的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+,MD=1e9+,INF=0x3f3f3f3f;
const ll LL_INF=0x3f3f3f3f3f3f3f3f;
const double eps=1e-,e=exp(),PI=acos(-.);
int a[],b[];
int main()
{
ios::sync_with_stdio(false),cin.tie(),cout.tie();
int T;
cin>>T;
while(T--)
{
for(int j=; j<; j++)b[j]=;
int n;
cin>>n;
for(int i=,x; i<n; i++)
{
cin>>x;
int l=;
while(x)l++,x>>=;
b[l-]++;
}
int ma=;
for(int i=;i<;i++)ma=max(ma,b[i]);
cout<<ma<<"\n";
}
return ;
}

Press the Button

ZOJ - 4056

BaoBao and DreamGrid are playing a game using a strange button. This button is attached to an LED light (the light is initially off), a counter and a timer and functions as follows:

  • When the button is pressed, the timer is set toseconds (no matter what the value of the timer is before the button is pressed), whereis a given integer, and starts counting down;

  • When the button is pressed with the LED light off, the LED light will be lit up;

  • When the button is pressed with the LED light on, the value of the counter will be increased by 1;

  • When the timer counts down to 0, the LED light turns off.

During the game, BaoBao and DreamGrid will press the button periodically. If the current real time (that is to say, the time elapsed after the game starts, NOT the value of the timer) in seconds is an integer and is a multiple of a given integer, BaoBao will immediately press the buttontimes; If the current time in seconds is an integer and is a multiple of another given integer, DreamGrid will immediately press the buttontimes.

Note that

  • 0 is a multiple of every integer;

  • Both BaoBao and DreamGrid are good at pressing the button, so it takes no time for them to finish pressing;

  • If BaoBao and DreamGrid are scheduled to press the button at the same second, DreamGrid will begin pressing the buttontimes after BaoBao finishes pressing the buttontimes.

The game starts at 0 second and ends afterseconds (if the button will be pressed atseconds, the game will end after the button is pressed). What's the value of the counter when the game ends?

Input

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

The first and only line contains six integers,,,,and(,). Their meanings are described above.

<h4< dd="">Output

For each test case output one line containing one integer, indicating the value of the counter when the game ends.

<h4< dd="">Sample Input

2
8 2 5 1 2 18
10 2 5 1 2 10

<h4< dd="">Sample Output

6
4

<h4< dd="">Hint

We now explain the first sample test case.

  • At 0 second, the LED light is initially off. After BaoBao presses the button 2 times, the LED light turns on and the value of the counter changes to 1. The value of the timer is also set to 2.5 seconds. After DreamGrid presses the button 1 time, the value of the counter changes to 2.

  • At 2.5 seconds, the timer counts down to 0 and the LED light is off.

  • At 5 seconds, after DreamGrid presses the button 1 time, the LED light is on, and the value of the timer is set to 2.5 seconds.

  • At 7.5 seconds, the timer counts down to 0 and the LED light is off.

  • At 8 seconds, after BaoBao presses the button 2 times, the LED light is on, the value of the counter changes to 3, and the value of the timer is set to 2.5 seconds.

  • At 10 seconds, after DreamGrid presses the button 1 time, the value of the counter changes to 4, and the value of the timer is changed from 0.5 seconds to 2.5 seconds.

  • At 12.5 seconds, the timer counts down to 0 and the LED light is off.

  • At 15 seconds, after DreamGrid presses the button 1 time, the LED light is on, and the value of the timer is set to 2.5 seconds.

  • At 16 seconds, after BaoBao presses the button 2 times, the value of the counter changes to 6, and the value of the timer is changed from 1.5 seconds to 2.5 seconds.

  • At 18 seconds, the game ends.

十分暴力找循环节的

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll q[];
int main()
{
int T;
cin>>T;
while(T--)
{
ll a,b,c,d,v,t;
cin>>a>>b>>c>>d>>v>>t;
ll lcm=a/__gcd(a,c)*c;
int tot=;
for(ll i=;i<=lcm;i+=a)q[tot++]=i;
for(ll i=;i<=lcm;i+=c)q[tot++]=i;
sort(q,q+tot);
tot=unique(q,q+tot)-q;
int tmp=;
for(int i=;i<tot;i++)if(q[i]-q[i-]>v)tmp++;
ll ans=(t/a)*b+(t/c)*d+b+d--t/lcm*tmp;
ll ma=t%lcm;
for(int i=;q[i]<=ma;i++)if(q[i]-q[i-]>v)ans--;
cout<<ans<<"\n";
}
return ;
}

感觉还是直接lcm比较好,复杂度比较低

The 2018 ACM-ICPC Asia Qingdao Regional Contest, Online的更多相关文章

  1. The 2018 ACM-ICPC Asia Qingdao Regional Contest(部分题解)

    摘要: 本文是The 2018 ACM-ICPC Asia Qingdao Regional Contest(青岛现场赛)的部分解题报告,给出了出题率较高的几道题的题解,希望熟悉区域赛的题型,进而对其 ...

  2. The 2018 ACM-ICPC Asia Qingdao Regional Contest

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

  3. ACM ICPC Central Europe Regional Contest 2013 Jagiellonian University Kraków

    ACM ICPC Central Europe Regional Contest 2013 Jagiellonian University Kraków Problem A: Rubik’s Rect ...

  4. 2019-2020 ICPC, Asia Jakarta Regional Contest (Online Mirror, ICPC Rules, Teams Preferred)

    2019-2020 ICPC, Asia Jakarta Regional Contest (Online Mirror, ICPC Rules, Teams Preferred) easy: ACE ...

  5. The 2018 ACM-ICPC Asia Qingdao Regional Contest, Online J - Press the Button(思维)

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=4056 题意 有一个按钮.一个灯.一个计时器和一个计数器,每按一次按钮,计时 ...

  6. The 2018 ACM-ICPC Asia Qingdao Regional Contest, Online -C:Halting Problem(模拟)

    C Halting Problem In computability theory, the halting problem is the problem of determining, from a ...

  7. The 2018 ACM-ICPC Asia Qingdao Regional Contest, Online Solution

    A    Live Love 水. #include<bits/stdc++.h> using namespace std; typedef long long ll; ; const i ...

  8. 2018-2019, ICPC, Asia Yokohama Regional Contest 2018 K

    传送门:https://codeforces.com/gym/102082/attachments 题解: 代码: /** * ┏┓ ┏┓ * ┏┛┗━━━━━━━┛┗━━━┓ * ┃ ┃ * ┃ ━ ...

  9. ZOJ - 4048 Red Black Tree (LCA+贪心) The 2018 ACM-ICPC Asia Qingdao Regional Contest, Online

    题意:一棵树上有m个红色结点,树的边有权值.q次查询,每次给出k个点,每次查询有且只有一次机会将n个点中任意一个点染红,令k个点中距离红色祖先距离最大的那个点的距离最小化.q次查询相互独立. 分析:数 ...

  10. 2018 ICPC Asia Jakarta Regional Contest

    题目传送门 题号 A B C D E F G H I J K L 状态 Ο . . Ο . . Ø Ø Ø Ø . Ο Ο:当场 Ø:已补 .  :  待补 A. Edit Distance Thin ...

随机推荐

  1. PHP实现正态分布的累积概率函数

    在实际项目中,遇到需要正态分布算法去计算一个数值在整体的分布区间,例如:  100,90,80,70,60,50,40,30,20,10共10个数,按从高到低的顺序排序,总数的10%分布区域为极高频, ...

  2. Docker搭建

    环境基于CentOS64位,内核最好3.10. 1.下载安装 docker      dockersudo yum install docker-io (假如内核版本太低的话,会在下载安装Docker ...

  3. Python+selenium之调用JavaScript

    webdriver提供了操作浏览器的前进和后退的方法,但是对于浏览器公东条并没有提供相应的操作方法.于是就需要借助JavaScript来控制浏览器的滚动条.webdriver提供了execute_sr ...

  4. CF 55D Beautiful numbers (数位DP)

    题意: 如果一个正整数能被其所有位上的数字整除,则称其为Beautiful number,问区间[L,R]共有多少个Beautiful number?(1<=L<=R<=9*1018 ...

  5. URAL 1057 Amount of Degrees (数位DP,入门)

    题意: 求给定区间[X,Y]中满足下列条件的整数个数:这个数恰好等于K个互不相等的,B的整数次幂之和.例如,设X=15,Y=20,K=2,B=2,则有且仅有下列三个数满足了要求:  17 = 24+2 ...

  6. 洛谷 P2905 [USACO08OPEN]农场危机Crisis on the Farm

    题目描述 约翰和他的奶牛组建了一只乐队“后街奶牛”,现在他们正在牧场里排练.奶牛们分成一堆 一堆,共1000)堆.每一堆里,30只奶牛一只踩在另一只的背上,叠成一座牛塔.牧场 里还有M(1 < ...

  7. 【Windows 10 v1703】解决桌面出现Removable Storage Devices的问题

    症状如下: 右键没有正常菜单,不能查看属性. 不能通过文件树找到这个文件夹. 出现原因不明. 暂时的解决方案: 右键,新建一个快捷方式.然后将快捷方式拖进垃圾桶,删除.这个文件夹将会被连带删除. 感谢 ...

  8. UVA 11853 - Paintball 战场(dfs)

    题意:有n个敌人,每个敌人有一个攻击范围,问你是否存在从西边到东边的路径,如果存在,输出入点和出点最靠北的坐标. 把每个敌人看出一个圆,从上往下跑dfs连通,如果到达底部,那么无解.要求出最靠北的坐标 ...

  9. MySQL 外键 表的查询

    自增补充 这是查看怎么创建的表, \G示旋转90度显示表的内容 表的自增的关键是** AUTO_INCREMENT=3**,在表中添加数据后,这个会自动改变,通过alert可以改变这个默认值 mysq ...

  10. fei33423 工作 职场 格言

    对老板: 1.  老板不知道你做的事情(目标设定) 2.  老板要的是规划(对上报告), 自己给自己设定 金字塔四位下的目标,各种维度.如何细化. 2.1 明确老板期望 2.2 与老板达成共识 2.3 ...