2018宁夏A题

As an ACM-ICPC newbie, Aishah is learning data structures in computer science. She has already known that a stack, as a data structure, can serve as a collection of elements with two operations:

  • push, which inserts an element to the collection, and
  • pop, which deletes the most recently inserted element that has not yet deleted.

Now, Aishah hopes a more intelligent stack which can display the maximum element in the stack dynamically. Please write a program to help her accomplish this goal and go through a test with several operations.

Aishah assumes that the stack is empty at first. Your program will output the maximum element in the stack after each operation. If at some point the stack is empty, the output should be zero.

Input

The input contains several test cases, and the first line is a positive integer TT indicating the number of test cases which is up to 5050.

To avoid unconcerned time consuming in reading data, each test case is described by seven integers n(1 \le n \le 5 \times 10^6),p,q,m(1 \le p,q,m \le 10^9),SA,SB \ and \ SC(10^4 \le SA,SB,SC \le 10^6)n(1≤n≤5×106),p,q,m(1≤p,q,m≤109),SA,SB and SC(104≤SA,SB,SC≤106). Theinteger nn is the number of operations, and your program should generate all operations using the following code in C++.

1

int n, p, q, m;

2

unsigned int SA, SB, SC;

3

unsigned int rng61() {

4

    SA ^= SA << 16;

5

    SA ^= SA >> 5;

6

    SA ^= SA << 1;

7

    unsigned int t = SA; SA = SB;

8

    SB = SC;

9

    SC ^= t ^ SA;

10

    return SC;

11

}

12

void gen(){

13

    scanf("%d%d%d%d%u%u%u", &n, &p, &q, &m, &SA, &SB, &SC);

14

    for(int i = 1; i <= n; i++) {

15

        if(rng61() % (p + q) < p)

16

            PUSH(rng61() % m + 1);

17

        else

18

            POP();

19

    }

20

}

The procedure PUSH(v) used in the code inserts a new element with value v into the stack and the procedure POP( ) pops the topmost element in the stack or does nothing if the stack is empty.

Output

For each test case, output a line containing Case #x: y, where xx is the test case number starting from 11, and yy is equal to \oplus^n_{i=1} (i \cdot a_i)⊕i=1n?(i⋅ai?) where a_iai? is the answer after the ii-th operation and \oplus⊕ means bitwise xor.

输出时每行末尾的多余空格,不影响答案正确性

样例输入复制

2
4 1 1 4 23333 66666 233333
4 2 1 4 23333 66666 233333

样例输出复制

Case #1: 19
Case #2: 1

样例解释

The first test case in the sample input has 44 operations:

  • POP();
  • POP();
  • PUSH(1);
  • PUSH(4).

The second test case also has 44 operations:

  • PUSH(2);
  • POP();
  • PUSH(1);
  • POP().

注意用longlong就可以了,这道题被一个空格卡了一天,复制的时候多了一个空格一直没有发现。实在是蠢死

#include <bits/stdc++.h>

using namespace std;

#define _for(i, a, b) for (int i = (a); i < (b); i++)

#define ll long long

const int N = 1e7;

int n, p, q, m;

unsigned int SA, SB, SC;

ll maxv, opr,t = 0, top;

ll ans[N];

stack<int> max_index;

void PUSH(unsigned x)

{

ans[top++] = x;

if (max_index.empty())

{

max_index.push(0);

}

else if (x > ans[max_index.top()])

{

max_index.push(top-1);

}else{

max_index.push(max_index.top());

}

opr = opr ^ (1LL * ans[max_index.top()] * t);

}

void POP()

{

if (max_index.empty())

return;

else

{

top--;

max_index.pop();

if (max_index.empty())

return;

opr = opr ^ (1LL * ans[max_index.top()] * t);

}

}

unsigned int rng61()

{

SA ^= SA << 16;

SA ^= SA >> 5;

SA ^= SA << 1;

unsigned int t = SA;

SA = SB;

SB = SC;

SC ^= t ^ SA;

return SC;

}

void gen()

{

scanf("%d%d%d%d%u%u%u", &n, &p, &q, &m, &SA, &SB, &SC);

top = 0;

_for(i, 1, n + 1)

{

if (rng61() % (p + q) < p)

{

++t;

PUSH(rng61() % m + 1);

}

else

{

++t;

POP();

}

}

}

int main()

{

int T;

cin >> T;

_for(i, 1, T + 1)

{

maxv = 0;

t = 0, opr = 0;

while (!max_index.empty())

{

max_index.pop();

}

gen();

printf("Case #%d: %lld\n", i, opr);

}

return 0;

}

As an ACM-ICPC newbie, Aishah is learning data structures in computer science. She has already known that a stack, as a data structure, can serve as a collection of elements with two operations:

  • push, which inserts an element to the collection, and
  • pop, which deletes the most recently inserted element that has not yet deleted.

Now, Aishah hopes a more intelligent stack which can display the maximum element in the stack dynamically. Please write a program to help her accomplish this goal and go through a test with several operations.

Aishah assumes that the stack is empty at first. Your program will output the maximum element in the stack after each operation. If at some point the stack is empty, the output should be zero.

Input

The input contains several test cases, and the first line is a positive integer TT indicating the number of test cases which is up to 5050.

To avoid unconcerned time consuming in reading data, each test case is described by seven integers n(1 \le n \le 5 \times 10^6),p,q,m(1 \le p,q,m \le 10^9),SA,SB \ and \ SC(10^4 \le SA,SB,SC \le 10^6)n(1≤n≤5×106),p,q,m(1≤p,q,m≤109),SA,SB and SC(104≤SA,SB,SC≤106). Theinteger nn is the number of operations, and your program should generate all operations using the following code in C++.

1

int n, p, q, m;

2

unsigned int SA, SB, SC;

3

unsigned int rng61() {

4

    SA ^= SA << 16;

5

    SA ^= SA >> 5;

6

    SA ^= SA << 1;

7

    unsigned int t = SA; SA = SB;

8

    SB = SC;

9

    SC ^= t ^ SA;

10

    return SC;

11

}

12

void gen(){

13

    scanf("%d%d%d%d%u%u%u", &n, &p, &q, &m, &SA, &SB, &SC);

14

    for(int i = 1; i <= n; i++) {

15

        if(rng61() % (p + q) < p)

16

            PUSH(rng61() % m + 1);

17

        else

18

            POP();

19

    }

20

}

The procedure PUSH(v) used in the code inserts a new element with value v into the stack and the procedure POP( ) pops the topmost element in the stack or does nothing if the stack is empty.

Output

For each test case, output a line containing Case #x: y, where xx is the test case number starting from 11, and yy is equal to \oplus^n_{i=1} (i \cdot a_i)⊕i=1n?(i⋅ai?) where a_iai? is the answer after the ii-th operation and \oplus⊕ means bitwise xor.

输出时每行末尾的多余空格,不影响答案正确性

样例输入复制

2
4 1 1 4 23333 66666 233333
4 2 1 4 23333 66666 233333

样例输出复制

Case #1: 19
Case #2: 1

样例解释

The first test case in the sample input has 44 operations:

  • POP();
  • POP();
  • PUSH(1);
  • PUSH(4).

The second test case also has 44 operations:

  • PUSH(2);
  • POP();
  • PUSH(1);
  • POP().

原文地址:https://www.cnblogs.com/zlwjy/p/11616223.html

时间: 2024-08-30 18:34:34

2018宁夏A题的相关文章

网络流板子/费用流板子 2018南京I题+2016青岛G题

2018南京I题: dinic,链式前向星,数组队列,当前弧优化,不memset全部数组,抛弃满流点,bfs只找一条增广路,每次多路增广 #include <bits/stdc++.h> #define ll long long #define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0) #define rep(ii,a,b) for(int ii=a;ii<=b;++ii) using namespace std; con

2018十二月刷题列表

Preface \(2018\)年的尾巴,不禁感慨自己这一年的蜕变只能用蜕变来形容了. 而且老叶说我们今年没的参加清北冬令营可以参加CCF在广州二中举办的冬令营,只要联赛\(390+\)就应该可以报. 想都不要想啊当然是要去的啦,可以跑到这么远的地方交流一下还可以逃过一月月考(\(2019.1.24\to2019.1.31\)) 瞬间感觉有了点实质性的东西刺激一下自己了,而且离\(ZJOI\),真的不远了... LIst Luogu P3704 [SDOI2017]数字表格 大力的套路反演,只不

2018 hncpc 部分题

A.字符画 签到 http://acm.csu.edu.cn:20080/csuoj/problemset/problem?pid=2163 #include<bits/stdc++.h> using namespace std; int w; void go(){ for(int i=1;i<=w;i++) cout<<"."; } int main(){ cin>>w; cout<<"ooo"; go();

阿里2018前端测评题(Promise异步流程控制)

用Promise控制异步流程,三个异步任务,时间可能有先后,但是要按照想要的顺序输出. 我这里用四种方法解决,其实也就是考察你对Promise的理解,基础题了. //实现mergePromise函数,把传进去的数组顺序先后执行, //并且把返回的数据先后放到数组data中 const timeout = ms => new Promise((resolve, reject) => { setTimeout(() => { resolve(); }, ms); }); const ajax

2018暑期做题部分整合

<Matrix>(HDU) 题意:n*m矩阵,每个点可黑可白,问有多少种方案使矩阵至少有A行B列全黑. 思路:第一反应当然是容斥,但是发现a+1行全黑的方案,并不是恰被a行全黑的方案多算a次,所以直接+1,-1,+1,-1这样的容斥系数就不可行. 而如果DP,复杂度太高,不可行. 于是考虑手推容斥系数,a行全黑的方案,被计数的次数取为([a>=A]-被更小的a计算次数)即可. 收获:对于复杂的计数问题,如果分类时,一种方案会在若干类中重复计数,可以使用推广的容斥来做. <Alway

2019东北四省B,G,H,J 2018宁夏 A,F

The 13th Chinese Northeast Collegiate Programming Contest B. Balanced Diet #include<bits/stdc++.h> #define il inline #define pb push_back #define fi first #define se second #define ms(_data,v) memset(_data,v,sizeof(_data)) #define sc(n) scanf("

2018上半年系统分析师真题及答案

系统分析师2018上半年真题及答案 (1)面向对象分析中,对象是类的实例.对象的构成成分包含了(1),属性和方法(或操作). A.标识 B.消息 C.规则 D.结构 参考答案[A] (2)UML2.0所包含的图中,(2) 描述由模型本身分解而成的组织单元,以及他们之间的依赖关系. A.组合结构图 B.包图 C.部署图 D.构件图 参考答案[B] (3)UML的结构包括构造块.规则和公共机制三个部分.在基本构造块中,(3)能够表示多个相互关联的事物的集合:规则是构造块如何放在一起的规定, 包括了(

【LeetCode】数学(共106题)

p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica } [2]Add Two Numbers [7]Reverse Integer [8]String to Integer (atoi) [9]Palindrome Number [12]Integer to Roman [13]Roman to Integer [29]Divide Two Integers [43]Multiply Strings [50]Pow(x,

计算机考研复试真题 简单计算器

题目描述 读入一个只包含 +, -, *, / 的非负整数计算表达式,计算该表达式的值. 输入描述:     测试输入包含若干测试用例,每个测试用例占一行,每行不超过200个字符,整数和运算符之间用一个空格分隔.没有非法表达式.当一行中只有0时输入结束,相应的结果不要输出. 输出描述:     对每个测试用例输出1行,即该表达式的值,精确到小数点后2位. 示例1 输入 1 + 2 4 + 2 * 5 - 7 / 11 0 输出 3.00 13.36 /* 天大2018考研编程题 程序设计思想: