Codeforces 821C Okabe and Boxes(模拟)】的更多相关文章

题目大意:给你编号为1-n的箱子,放的顺序不定,有n条add指令将箱子放入栈中,有n条remove指令将箱子移除栈,移出去的顺序是从1-n的,至少需要对箱子重新排序几次. 解题思路:可以通过把栈清空表示已经排过序了,如果下一次remove时栈为空,说明已经排序过且没有新的箱子放入,因为题目确保在需要删除之前添加每个箱子,所以肯定栈顶的箱子是我们所需要的.如果栈不为空则判断栈顶箱子序号是否是我们需要的,不是则重新排序,用清空栈来表示. 这里用数字模拟了栈. #include<iostream>…
821C - Okabe and Boxes 思路:模拟.因为只需要比较栈顶和当前要删除的值就可以了,所以如果栈顶和当前要删除的值不同时,栈就可以清空了(因为下一次的栈顶不可能出现在前面那些值中). 代码: #include<bits/stdc++.h> using namespace std; #define ll long long vector<int>st; int main() { ios::sync_with_stdio(false); cin.tie(); ,ans=…
C. Okabe and Boxes 这个题目是一个有点思维的模拟,当时没有想到, 思维就是这个栈的排序这里,因为每次直接排序肯定会t的,所以不可以这么写,那怎么表示排序呢? 就是直接把栈清空,如果栈顶就是我们需要的这个值,那就把这个值直接pop, 但是如果不是呢,就可以直接清空这个栈表示排序,如果栈已经是空的了,说明之前排过序了. 如果不是那就清空(排序),这个有点难想. #include <cstdio> #include <cstring> #include <cstd…
C. Okabe and Boxes time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Okabe and Super Hacker Daru are stacking and removing boxes. There are n boxes numbered from 1 to n. Initially there are…
CodeForces.158A Next Round (水模拟) 题意分析 校赛水题的英文版,坑点就是要求为正数. 代码总览 #include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #include <sstream> #include <set> #include <map> #include <queue>…
C. Balls and Boxes time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Little Vasya had n boxes with balls in the room. The boxes stood in a row and were numbered with numbers from 1 to n from…
C. Boxes Packing time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Mishka has got n empty boxes. For every i (1 ≤ i ≤ n), i-th box is a cube with side length ai. Mishka can put a box i into a…
[题目链接]:http://codeforces.com/contest/821/problem/C [题意] 给你2*n个操作; 包括把1..n中的某一个数压入栈顶,以及把栈顶元素弹出; 保证压入和弹出操作都恰好各n个; 且压入的n个数字都各不相同; 在弹出栈的时候你可以把栈中的元素重新排列; 要求弹出的数形成的数列恰好组成1..n; 问你最少需要重新排列多少次; [题解] 对于每一个remove操作,其实已经能确定接下来要输出的是几了; 在进行重新排操作的时候; 你可以假定自己"很聪明&qu…
Link 题意:给出操作,如果当前出栈操作使得出栈序列非顺序,可以在此之前自由排序栈中所有数,问最少排几次. 思路:已经出栈到第x个元素时,每次需要排序的操作后,能够保证前x元素出栈有序,否则说明该操作序列根本无法做到有序出栈.所以碰到不合顺序的数,将栈中所有元素出栈一遍即可. /** @Date : 2017-07-04 15:21:52 * @FileName: C.cpp * @Platform: Windows * @Author : Lweleth (SoungEarlf@gmail.…
http://codeforces.com/problemset/problem/747/C 题意:有n台机器,q个操作.每次操作从ti时间开始,需要ki台机器,花费di的时间.每次选择机器从小到大开始,如果可以完成任务,那么输出id总和,否则输出-1. 思路:简单的模拟,注意如果不能完成任务,那么ser数组是不能更新的. #include <cstdio> #include <algorithm> #include <iostream> #include <cs…