CodeForces 42C Safe cracking 规律题
题目链接:点击打开链接
3个数为一组,找最大的一个数让它降低,则显然是有解的,分类讨论一下就可以
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<vector>
using namespace std;
int n, k;
int a[4];
vector<pair<int,int> >ans;
int maxpos(){
int pos = 0;
for(int i = 1; i < 4; i++)
if(a[pos]<a[i])pos = i;
return pos;
}
void chu(int pos){
a[pos] >>= 1; a[(pos+1)%4] >>= 1;
ans.push_back(pair<int,int>(0, pos));
}
void ADD(int pos){
a[pos] ++; a[(pos+1)%4] ++;
ans.push_back(pair<int,int>(1, pos));
}
int main(){
while(cin>>a[0]>>a[1]>>a[2]>>a[3]){
ans.clear();
int pos, siz = 0;
while(1){
pos = maxpos();
if(a[pos]==1)return true;
int l = pos-1; if(l<0)l = 3;
int r = pos+1; if(r>3)r = 0;
if(a[pos]&1){
if(a[l]&1)
{
ADD(l);
chu(l);
}
else if(a[r]&1)
{
ADD(pos);
chu(pos);
}
else {
ADD(pos);
chu(l);
}
}
else {
if((a[l]&1)==0)
{
chu(l);
}
else if((a[r]&1)==0)
{
chu(pos);
}
else {
ADD(l); ADD(pos);
chu(l);
}
}
}
for(int i = 0; i < ans.size(); i++)
printf("%c%d\n", ans[i].first?'+':'/', ans[i].second+1);
}
return 0;
}
CodeForces 42C Safe cracking 规律题的更多相关文章
- Codeforces 480B Long Jumps 规律题
题目链接:点击打开链接 题意: 输出n l x y 有一根直尺长度为l 上面有n个刻度. 以下n个数字是距离开头的长度(保证第一个数字是0,最后一个数字是l) 要使得 直尺中存在某2个刻度的距离为x ...
- Codeforces - 规律题 [占坑]
发现自己容易被卡水题,需要强行苟一下规律题 CF上并没有对应的tag,所以本题集大部分对应百毒搜索按顺序刷 本题集侧重于找规律的过程(不然做这些垃圾题有什么用) Codeforces - 1008C ...
- LightOJ1010---Knights in Chessboard (规律题)
Given an m x n chessboard where you want to place chess knights. You have to find the number of maxi ...
- ACM_送气球(规律题)
送气球 Time Limit: 2000/1000ms (Java/Others) Problem Description: 为了奖励近段时间辛苦刷题的ACMer,会长决定给正在机房刷题的他们送气球. ...
- hdoj--1005--Number Sequence(规律题)
Number Sequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- Codeforces#441 Div.2 四小题
Codeforces#441 Div.2 四小题 链接 A. Trip For Meal 小熊维尼喜欢吃蜂蜜.他每天要在朋友家享用N次蜂蜜 , 朋友A到B家的距离是 a ,A到C家的距离是b ,B到C ...
- You Are Given a Decimal String... CodeForces - 1202B [简单dp][补题]
补一下codeforces前天教育场的题.当时只A了一道题. 大致题意: 定义一个x - y - counter :是一个加法计数器.初始值为0,之后可以任意选择+x或者+y而我们由每次累加结果的最后 ...
- codeforces 1165F1/F2 二分好题
Codeforces 1165F1/F2 二分好题 传送门:https://codeforces.com/contest/1165/problem/F2 题意: 有n种物品,你对于第i个物品,你需要买 ...
- Codeforces 959E. Mahmoud and Ehab and the xor-MST 思路:找规律题,时间复杂度O(log(n))
题目: 解题思路 这题就是0,1,2...n-1总共n个数字形成的最小生成树. 我们可以发现,一个数字k与比它小的数字形成的异或值,一定可以取到k与所有正整数形成的异或值的最小值. 要计算n个数字的情 ...
随机推荐
- JavaScript常用語句
1.document.write(""); 输出语句2.JS中的注释为//3.传统的HTML文档顺序是: document->html->(head,body)4 ...
- Android中 单位 介绍
看到有很多网友不太理解dp.sp和px的区别:现在这里介绍一下dp和sp.dp也就是dip.这个和sp基本类似.如果设置表示长度.高度等属性时可以使用dp 或sp.但如果设置字体,需要使用sp.dp是 ...
- Linux命令-文件处理命令:tail
tail /etc/services 查看etc目录的services文件最后10行内容(默认显示后10行内容) tail -n /etc/services 查看etc目录的services文件的后5 ...
- pandas contact 之后,若要用到index列,要记得用reset_index去处理index
# -*- coding: utf-8 -*- import pandas as pd import sys df1 = pd.DataFrame({ 'A': ['A0', 'A1', 'A2', ...
- Redis配置和常用命令
redis.conf配置文件: 引用 #是否作为守护进程运行 daemonize yes #配置pid的存放路径及文件名,默认为当前路径下 pidfile redis.pid #Redis默认监听端口 ...
- Graphics View框架
Qt4.2开始引入了Graphics View框架用来取代Qt3中的Canvas模块,并在很多地方作了改进,Graphics View框架实现了模型-视图结构的图形管理,能对大量图元进行管理,支持碰撞 ...
- javaweb reponse 写出文件
Map map = getSearchValue(); File excelFile = orderService.getexportexcel(id,map); InputStream is = n ...
- ural1517后缀数组
题意:求两串字符(0————255)的最长公共字串 思路:先将两个字符链接起来,中间用一个不曾出现过的字符,然后直接求出height数组,然后根据它的特性,求出最长的公共字串,当然这个最长公共字串的坐 ...
- php服务器环境变量
可以把一些配置写到apache或nginx的配置里,然后在代码里判断环境变量来实现开发环境和线上环境的切换. 比如在本地可以 SetEnv APP_ENV local线上则 SetEnv APP_EN ...
- Android——excise(用线性布局、表格布局、相对布局做发送邮件界面)
LinearLayout <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns ...