B - B

CodeForces - 879B

n people are standing in a line to play table tennis. At first, the first two players in the line play a game. Then the loser goes to the end of the line, and the winner plays with the next person from the line, and so on. They play until someone wins k games in a row. This player becomes the winner.

For each of the participants, you know the power to play table tennis, and for all players these values are different. In a game the player with greater power always wins. Determine who will be the winner.

Input

The first line contains two integers: n and k (2 ≤ n ≤ 500, 2 ≤ k ≤ 1012) — the number of people and the number of wins.

The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ n) — powers of the player. It's guaranteed that this line contains a valid permutation, i.e. all ai are distinct.

Output

Output a single integer — power of the winner.

Examples

Input
2 2
1 2
Output
2 
Input
4 2
3 1 2 4
Output
3 
Input
6 2
6 5 3 1 2 4
Output
6 
Input
2 10000000000
2 1
Output
2

Note

Games in the second sample:

3 plays with 1. 3 wins. 1 goes to the end of the line.

3 plays with 2. 3 wins. He wins twice in a row. He becomes the winner.

题意:有n个人排成一排比赛,给出了每个人的武力值,开始时前两个人打,输的人去队伍后面,赢的人接着和下一个人打,以此类推,直至有人连赢k场,比赛结束,输出该人的能力值。

需要用long long

思路:从头遍历一遍,如果有人赢得了k场则输出,如果没有那一定是武力值最大的人,直接输出即可。

一开始就按照题目中的来遍历,把输的值排到后面,扩大数组长度,直到某个人武力值达到要求结束遍历,但在测试点18wa掉了,然后就按照上面这个思路来做,也没有直接对,用错了步骤方法,又改了几遍才对。

#include<bits/stdc++.h>
using namespace std;
int main()
{
long long n;
long long k;
cin>>n>>k;
long long s[2*n]={0},b[2*n]={0},minn=-1;
for(long long i=0;i<n;i++)
{
cin>>s[i];
minn=max(minn,s[i]);
}
long long ct=0,i,j;
for( j=0;j<n;j++)
{
if(j!=0&&s[j]>s[j-1])
{
ct=1;
}
else{
ct=0;
}
for(i=j+1;i<n;i++)
{
if(s[j]>s[i])ct++;
else break;
}
if(ct>=k)
{
cout<<s[j]<<endl;
break;
}
}
if(j>=n)
{
cout<<minn<<endl;
}
}

C - C

CodeForces - 879C

Petya learned a new programming language CALPAS. A program in this language always takes one non-negative integer and returns one non-negative integer as well.

In the language, there are only three commands: apply a bitwise operation AND, OR or XOR with a given constant to the current integer. A program can contain an arbitrary sequence of these operations with arbitrary constants from 0 to 1023. When the program is run, all operations are applied (in the given order) to the argument and in the end the result integer is returned.

Petya wrote a program in this language, but it turned out to be too long. Write a program in CALPAS that does the same thing as the Petya's program, and consists of no more than 5 lines. Your program should return the same integer as Petya's program for all arguments from 0 to 1023.

Input

The first line contains an integer n (1 ≤ n ≤ 5·105) — the number of lines.

Next n lines contain commands. A command consists of a character that represents the operation ("&", "|" or "^" for AND, OR or XOR respectively), and the constant xi 0 ≤ xi ≤ 1023.

Output

Output an integer k (0 ≤ k ≤ 5) — the length of your program.

Next k lines must contain commands in the same format as in the input.

Examples

Input
3
| 3
^ 2
| 1
Output
2
| 3
^ 2
Input
3
& 1
& 3
& 5
Output
1
& 1
Input
3
^ 1
^ 2
^ 3
Output
0

Note

You can read about bitwise operations in https://en.wikipedia.org/wiki/Bitwise_operation.

Second sample:

Let x be an input of the Petya's program. It's output is ((x&1)&3)&5 = x&(1&3&5) = x&1. So these two programs always give the same outputs.

题意:给出一个n,然后紧接着跟着n行的程序,每一行含有一个操作符和一个操作数,操作符只有三种与,或,异或。同时规定所有的操作数都在0-1023之间。要求把给出的程序缩短,缩短到5行之内。

自己做的时候理解错了题意,以为是把相同的运算符简化再直接输出,但看了别人的也没有很理解。。。。

我的错误代码:

#include<bits/stdc++.h>
#define N 500005
using namespace std;
int main()
{
map<char,int>mp;
int n;
cin>>n;
char ch;
int k[N];
for(int i=0;i<n;i++)
{
cin>>ch>>k[i];
if(mp[ch]==0)mp[ch]=k[i];
else
{
if(ch=='|')
{
mp[ch]|=k[i];
}
else if(ch=='^')mp[ch]^=k[i];
else if(ch=='&')mp[ch]&=k[i];
}
}
int m=mp.size();
if(mp['|']==0&&mp['&']==0&&mp['^']==0) cout<<"0"<<endl;
else{
cout<<m<<endl;
// cout<<"^ "<<mp['^']<<"*"<<endl;
if(mp['|']!=0)cout<<"| "<<mp['|']<<endl;
if(mp['^']!=0)cout<<"^ "<<mp['^']<<endl;
if(mp['&']!=0)cout<<"& "<<mp['&']<<endl;
}
}

(别人的)正确思路:位运算的等价变换

链接:(具体)

https://www.cnblogs.com/siuginhung/p/7743536.html

正确代码:#include<bits/stdc++.using namespace std;

int main()
{
int a,b;
a = 0,b = 1023;
int n;
scanf("%d",&n);
char s[100];
int num;
while(n--)
{
scanf("%s%d",s,&num);
if(s[0] == '|')
{
a |= num;
b |= num;
}
else if(s[0] == '&')
{
a &= num;
b &= num;
}
else if(s[0] == '^')
{
a ^= num;
b ^= num;
}
}
int x=0,y=0,z=0;
x=a | b;
y=a & b;
z=a & (b ^ 1023);
printf("3\n");
printf("| %d\n",y);
printf("& %d\n",x);
printf("^ %d\n",z);

}

2021.1.23--vj补题的更多相关文章

  1. 2021.5.22 vj补题

    A - Marks CodeForces - 152A 题意:给出一个学生人数n,每个学生的m个学科成绩(成绩从1到9)没有空格排列给出.在每科中都有成绩最好的人或者并列,求出最好成绩的人数 思路:求 ...

  2. Educational Codeforces Round 23 A-F 补题

    A Treasure Hunt 注意负数和0的特殊处理.. 水题.. 然而又被Hack了 吗的智障 #include<bits/stdc++.h> using namespace std; ...

  3. QFNU-ACM 2021.10.09 Rating补题

    A - A CodeForces - 478A 注意点: 和为0时要特判一下. 代码: #include<bits/stdc++.h> using namespace std; int m ...

  4. 2021-5-15 vj补题

    C - Win or Freeze CodeForces - 151C 题目内容: You can't possibly imagine how cold our friends are this w ...

  5. 20165237 2017-2018-2 《Java程序设计》第四周考试补做及2-3章编程题

    20165237 2017-2018-2 <Java程序设计>第四周考试补做及2-3章编程题 测试JDB: 用JDB调试上一个程序,输入1.2.3: 2-3章编程题代码托管 (程序的运行结 ...

  6. 2020.12.20vj补题

    A - Insomnia cure 题意:一共s只龙,每隔k,l,m,n只龙就会受伤,问这s只龙有多少龙是受伤的 思路:看起来题目范围并不是很多,直接进行循环判断 代码: 1 #include< ...

  7. hdu5017:补题系列之西安网络赛1011

    补题系列之西安网络赛1011 题目大意:给定一个椭球: 求它到原点的最短距离. 思路: 对于一个椭球的标准方程 x^2/a^2 + y^2/b^2 +z^2/c^2=1 来说,它到原点的最短距离即为m ...

  8. 2017河工大校赛补题CGH and 赛后小结

    网页设计课上实在无聊,便开始补题,发现比赛时候僵着的东西突然相通了不少 首先,"追妹"这题,两个队友讨论半天,分好多种情况最后放弃(可是我连题目都没看啊),今天看了之后试试是不是直 ...

  9. 2018 HDU多校第四场赛后补题

    2018 HDU多校第四场赛后补题 自己学校出的毒瘤场..吃枣药丸 hdu中的题号是6332 - 6343. K. Expression in Memories 题意: 判断一个简化版的算术表达式是否 ...

  10. 2018 HDU多校第三场赛后补题

    2018 HDU多校第三场赛后补题 从易到难来写吧,其中题意有些直接摘了Claris的,数据范围是就不标了. 如果需要可以去hdu题库里找.题号是6319 - 6331. L. Visual Cube ...

随机推荐

  1. 基于CentOS7.x Linux操作系统,从0开始构建一套Docker虚拟化平台,使用二进制Tar包方式,部署的步骤和方法如下:

    #配置centos7的yum源#建议阿里源#链接:https://yq.aliyun.com/articles/525282?type=2#从Docker官网下载软件包: ls -l docker-1 ...

  2. 聚类算法与K-means实现

    聚类算法与K-means实现 一.聚类算法的数学描述: 区别于监督学习的算法(回归,分类,预测等),无监督学习就是指训练样本的 label 未知,只能通过对无标记的训练样本的学习来揭示数据的内在规律和 ...

  3. 单片机学习(十一)I2C总线和AT24C02的使用

    一. 存储器介绍 存储器分类图 1. RAM 这类存储器中的数据都是掉电即失的,例如计算机中的内存就是DRAM,但它们数据读写速度都是要比ROM要快得多的. SRAM:本质是电路,使用电路构成的触发器 ...

  4. 《DotNet Web应用单文件部署系列》一、pubxml文件配置

    很多人想用DotNet开发软件赚点外快子补添家用,但心里总放不下心来,担心被人破解了.好消息是去年发布的DotNet 5支持单文件部署,不同于DotNet 3运行时将文件释放到临时文件夹内,DotNe ...

  5. 经典多级时间轮定时器(C语言版)

    经典多级时间轮定时器(C语言版) 文章目录 经典多级时间轮定时器(C语言版) 1. 序言 2. 多级时间轮实现框架 2.1 多级时间轮对象 2.2 时间轮对象 2.3 定时任务对象 2.4 双向链表 ...

  6. Dart简易教程 (1)---数据类型 运算符,类转换换

    从下面开始学习DART编程 以下是一个简单的示例: main(){ var number = 42; print(number);}程序说明,dart是一个强大的脚本类语言,可以不预先定义变量类型 , ...

  7. CodeForce-812C Sagheer and Nubian Market(二分)

    Sagheer and Nubian Market CodeForces - 812C 题意:n个货物,每个货物基础价格是ai. 当你一共购买k个货物时,每个货物的价格为a[i]+k*i. 每个货物只 ...

  8. WebView(网页视图)基本用法

    资料来源于菜鸟教程 啊这官方文档居然失效了,打不开.那我们直接就看相关方法: WebChromeClient:辅助WebView处理Javascript的对话框.网站图标.网站title.加载进度等! ...

  9. mybatis一对一联表查询的两种常见方式

    1.一条语句执行查询(代码如下图)  注释:class表(c别名),teacher表(t别名)teacher_id为class表的字段t_id为teacher表的字段,因为两者有主键关联的原因,c_i ...

  10. Jmeter系类(31) - JSR223(1) | 控件介绍

    JSR233 介绍 JSR223控件执行JSR223脚本代码用于创建/更新所需的某些变量 JSR223可以使用其内置的变量,有助于精简脚本,提高开发测试的效率 由于JSR223脚本编译方式基本相同,J ...