codeforce 985A Chess Placing(暴力)】的更多相关文章

Chess Placing time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are given a chessboard of size 1 × n. It is guaranteed that n is even. The chessboard is painted like this: "BWBW...BW"…
题意: 移动最少的步数,使得所有的棋子在同一颜色的格子中. 每次一个棋子只能向左或者向右移动一步,不能移到有棋子的格子中. 思路: 枚举全黑和全白的情况. 对于每一个需要移动的棋子,它移动到的位置一定是从1开始第一个可以移动的位置,不交叉移动,保证了步数最小. 代码: #include <stdio.h> #include <string.h> #include <algorithm> using namespace std; ; int v[N],g[N]; int…
You are given a chessboard of size 1 × n. It is guaranteed that n is even. The chessboard is painted like this: "BWBW...BW". Some cells of the board are occupied by the chess pieces. Each cell contains no more than one chess piece. It is known t…
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #define N 500005 using namespace std; typedef long long LL; LL prefix[N], suffix[N], num[N]; LL cntSuf[N]; int main(){ int n; scanf("%d", &n);…
链接 [https://codeforces.com/contest/985/problem/A] 题意 给你一个偶数n,输入n/2个数,代表棋子的位置,有一个1*n的棋盘是黑白相间的 问你使得所有棋子在同一种颜色所需移动的最小步数 分析 先对所有棋子的位置排序 贪心枚举两种颜色都算在比较 代码 #include<bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define mp ma…
[链接]:CF985A [题意]:给你n和n/2个数ai,每个ai和奇数.偶数比较距离(注意选了奇数,偶数的距离就不要算了,反之同理),求最小的答案. [代码]: #include <iostream> #include<queue> #include<string.h> #include<bits/stdc++.h> using namespace std; #define N 100010 #define M 2005 const int INF = 0…
题目链接:https://codeforces.com/contest/985 ’A.Chess Placing 题意:给了一维的一个棋盘,共有n(n必为偶数)个格子.棋盘上是黑白相间的.现在棋盘上有n/2个棋子,让你全部移动到黑色格子或者白色格子,要求步数最少,并输出步数. 题解:由于黑色或者白色都是固定位置,我们对棋子位置排个序,然后全部移动到任意一个颜色,取两个最小步数的最小值就好了. #include<bits/stdc++.h> #define clr(x) memset(x,0,s…
11.12.2018 逆向暴力求解 538.D Weird Chess New Point: 没有读好题 越界的情况无法判断,所以输出任何一种就可以 所以他给你的样例输出完全是误导 输出还搞错了~ 输出的举证中间竟然空格隔开每一个字符,真的是不该错,否则应该是1A吧 然后空间开小了,地图空间倒是注意到了,但是你存取’o’的空间只有1000,而地图大小最大是50*50所以最多是2500个’o’的地址 中间的选择代码逻辑有些混乱 要加强练习! Describe: 定义新的下棋游戏,给你多个棋子’o’…
CodeForce 855B 暴力or线段树 题意 给你一串数,然后找出三个数,他们的前后关系和原来一样,可以相同,然后分别乘p,q,r,求他们积的和最大,并且输出这个数. 解题思路 这个可以使用线段树来做,找出区间内的最小值和最大值,如果x(代表pqr中的一个)小于零,就乘以这个区间的最小值,如果大于零,就乘以这个区间的最大值.然后\(j\)从1到n开始遍历. 或者可以暴力,不过这个暴力比一点重方法还要好,我看完就惊呆了,lxm大佬太强了. 代码实现 第一种: #include<cstdio>…
题目描述 Iahub and Sorin are the best competitive programmers in their town. However, they can't both qualify to an important contest. The selection will be made with the help of a single problem. Blatnatalag, a friend of Iahub, managed to get hold of th…