杭电的题,输出格式卡的很严。HDU 1716 排列2
题很简单,一开始写代码,是用整数的格式写的,怎么跑都不对,就以为算法错了,去看大佬们的算法STL全排列:next_permutation(); 又双叒叕写了好几遍,PE了将近次,直到跑了大佬代码发现,原来格式是这样的。
下面是实现全排列的两段代码,睡觉睡觉。
STL电动
#include<iostream>
#include<cstdio>
#include<cstring>
#include<map>
#include<set>
#include<algorithm>
using namespace std;
int main()
{
char a[4]={0};
int x=0;
for(;;)
{
for(int i=0;i<4;i++)
{
cin>>a[i];
}
sort(a,a+4);
char w=a[0];
if(a[0]=='0'&&a[1]=='0'&&a[3]=='0'&&a[2]=='0') break;
if(x) cout<<endl;
x++;
int qt=0;
int lasta0=-1;
bool flag2=true;
do {
if(a[0]=='0')continue;
if(flag2)flag2 = false;
else if(a[0] == lasta0) cout<<' ';
else cout<<endl;
cout<<a[0]<<a[1]<<a[2]<<a[3];
lasta0 = a[0];
} while(next_permutation(a, a +4));
cout<<endl;
}
return 0;
}
纯手动
#include<iostream>
#include<cstdio>
#include<cstring>
#include<map>
#include<set>
#include<algorithm>
using namespace std;
set<int> mx;
int main()
{
int a[5];
int sb=0;
for(;;)
{
mx.clear();
int multi;
for(int i=1;i<5;i++)
{
cin>>a[i];
}
if(a[1]==0&&a[2]==0&&a[3]==0&&a[4]==0) break;
if(sb)cout<<endl;
sb++;
for(int i=1;i<5;i++)
{
for(int j=1;j<5;j++)
{
if(i==j) continue;
for(int k=1;k<5;k++)
{
if(j==k||i==k) continue;
for(int l=1;l<5;l++)
{
if(k==l||l==j||l==i) continue;
multi=a[i]*1000+a[j]*100+a[k]*10+a[l];
if(multi>999) mx.insert(multi);
}
}
}
}
set<int>::iterator poi,p2;
p2=mx.begin();
int xa=0;
for(poi=mx.begin();poi!=mx.end();poi++)
{
p2++;
if(xa) cout<<' ';
xa++;
cout<<*poi;
if(*p2/1000!=*poi/1000)
{
cout<<endl;
xa=0;
}
}
}
return 0;
}
杭电的题,输出格式卡的很严。HDU 1716 排列2的更多相关文章
- 高手看了,感觉惨不忍睹——关于“【ACM】杭电ACM题一直WA求高手看看代码”
按 被中科大软件学院二年级研究生 HCOONa 骂为“误人子弟”之后(见:<中科大的那位,敢更不要脸点么?> ),继续“误人子弟”. 问题: 题目:(感谢 王爱学志 网友对题目给出的翻译) ...
- Help Johnny-(类似杭电acm3568题)
Help Johnny(类似杭电3568题) Description Poor Johnny is so busy this term. His tutor threw lots of hard pr ...
- 杭电oj2093题,Java版
杭电2093题,Java版 虽然不难但很麻烦. import java.util.ArrayList; import java.util.Collections; import java.util.L ...
- acm入门 杭电1001题 有关溢出的考虑
最近在尝试做acm试题,刚刚是1001题就把我困住了,这是题目: Problem Description In this problem, your task is to calculate SUM( ...
- 杭电dp题集,附链接还有解题报告!!!!!
Robberies 点击打开链接 背包;第一次做的时候把概率当做背包(放大100000倍化为整数):在此范围内最多能抢多少钱 最脑残的是把总的概率以为是抢N家银行的概率之和- 把状态转移方程写成了f ...
- 杭电ACM题单
杭电acm题目分类版本1 1002 简单的大数 1003 DP经典问题,最大连续子段和 1004 简单题 1005 找规律(循环点) 1006 感觉有点BT的题,我到现在还没过 1007 经典问题,最 ...
- 杭电60题--part 1 HDU1003 Max Sum(DP 动态规划)
最近想学DP,锻炼思维,记录一下自己踩到的坑,来写一波详细的结题报告,持续更新. 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1003 Problem ...
- 杭电21题 Palindrome
Problem Description A palindrome is a symmetrical string, that is, a string read identically from le ...
- 杭电20题 Human Gene Functions
Problem Description It is well known that a human gene can be considered as a sequence, consisting o ...
随机推荐
- scrapy中使用selenium来爬取页面
scrapy中使用selenium来爬取页面 from selenium import webdriver from scrapy.http.response.html import HtmlResp ...
- PHPDocumentor2.8.5 安装,使用及快速上手
PHPDocumentor当前版本是phpDocumentor-2.8.5.tgz 关于PHPDocumentor有什么用,还有其历史,我就不介绍了,直接进入正题.老版本的叫PHPDoc,从1.0开始 ...
- Pytest系列(16)- 分布式测试插件之pytest-xdist的详细使用
如果你还想从头学起Pytest,可以看看这个系列的文章哦! https://www.cnblogs.com/poloyy/category/1690628.html 前言 平常我们功能测试用例非常多时 ...
- 在OS X环境下MySQL启动时报错
--03T00::.483037Z [ERROR] InnoDB: Unable to lock ./ibdata1 error: --03T00::.483100Z [Note] InnoDB: C ...
- Array(数组)对象-->concat() 方法
1.定义和用法 concat() 方法用于连接两个或多个字符串. 语法: string.concat(string1, string2, ..., stringX) 举例: var str1='hel ...
- Linux忘记密码解决方案
Linux 忘记密码解决方法 很多朋友经常会忘记Linux系统的root密码,linux系统忘记root密码的情况该怎么办呢?重新安装系统吗?当然不用!进入单用户模式更改一下root密码即可. 步骤如 ...
- http的请求头都有那些信息
每个HTTP请求和响应都会带有相应的头部信息.默认情况下,在发送XHR请求的同时,还会发送下列头部信息: Accept:浏览器能够处理的内容类型 Accept-Charset:浏览器能够显示的字符集 ...
- Git把本地代码推送到远程github仓库
运用Git版本控制系统进行代码的管理,以便于团队成员的协作,由于之前是使用svn来进行版本控制,所以对于Git使用还有待熟练掌握.Git与svn类似,个人认为两者之间比较直观的区别就是 Git 不需要 ...
- [Laravel] 自带分页实现以及links方法不存在错误
自带分页实现其实挺简单的,但是我在实现的时候报错!找了很久才找出原因! 废话不说上码 控制器LeeController.php层 <?php namespace App\Http\control ...
- python-Django与Apache整合wsgi模块
1.安装wsgi模块 yum search mod_wsgi yum install -y mod_wsgi 2.会在httpd下有配置文件 cd /etc/httpd/conf.d/wsgi.con ...