HDU 5402 (构造题)Travelling Salesman Problem
来源:互联网 发布:怎样申请淘宝开网店 编辑:程序博客网 时间:2024/06/06 19:04
题意
略。
思路
比赛的时候其实已经意识到是一个构造题了。
蓝儿m,n都是偶数的时候搞崩了。sad。。
m,n有一个是奇数不说了,可以走完所有。
两个都是偶数的时候,我们就去找一个最小的值且它的位置坐标和是奇数,然后就绕开这个走。其他都可以走完辣。
参考code:
/* #pragma warning (disable: 4786) #pragma comment (linker, "/STACK:0x800000") */#include <cassert>#include <cctype>#include <cmath>#include <cstdio>#include <cstdlib>#include <cstring>#include <iostream>#include <sstream>#include <iomanip>#include <string>#include <vector>#include <list>#include <set>#include <map>#include <stack>#include <queue>#include <algorithm>#include <iterator>#include <utility>using namespace std;template< class T > T _abs(T n){ return (n < 0 ? -n : n);}template< class T > T _max(T a, T b){ return (!(a < b) ? a : b);}template< class T > T _min(T a, T b){ return (a < b ? a : b);}template< class T > T sq(T x){ return x * x;}template< class T > T gcd(T a, T b){ return (b != 0 ? gcd<T>(b, a%b) : a);}template< class T > T lcm(T a, T b){ return (a / gcd<T>(a, b) * b);}template< class T > bool inside(T a, T b, T c){ return a<=b && b<=c;}#define MIN(a, b) ((a) < (b) ? (a) : (b))#define MAX(a, b) ((a) > (b) ? (a) : (b))#define F(i, n) for(int (i)=0;(i)<(n);++(i))#define rep(i, s, t) for(int (i)=(s);(i)<=(t);++(i))#define urep(i, s, t) for(int (i)=(s);(i)>=(t);--(i))#define repok(i, s, t, o) for(int (i)=(s);(i)<=(t) && (o);++(i))#define MEM0(addr) memset((addr), 0, sizeof((addr)))#define MP(x, y) make_pair(x, y)#define REV(s, e) reverse(s, e)#define SET(p) memset(pair, -1, sizeof(p))#define CLR(p) memset(p, 0, sizeof(p))#define MEM(p, v) memset(p, v, sizeof(p))#define CPY(d, s) memcpy(d, s, sizeof(s))#define READ(f) freopen(f, "r", stdin)#define WRITE(f) freopen(f, "w", stdout)#define SZ(c) (int)c.size()#define PB(x) push_back(x)#define ff first#define ss second#define ll long long#define ld long double#define pii pair< int, int >#define psi pair< string, int >#define ls u << 1#define rs u << 1 | 1#define lson l, mid, u << 1#define rson mid, r, u << 1 | 1#define debug(x) cout << #x << " = " << x << endlconst int N = 110, M = 510;const double PI = acos(-1.0);const int maxn = 110;const int maxm = maxn * maxn;const int inf = 1 << 29;const ll mod = 3221225473;const double eps = 1e-10;ll t,m,n,a[maxn][maxn],sum,x,y;void get(){ x = 1;y = 2; rep(i,1,n){ rep(j,1,m){ if( ((i + j) & 1) && a[x][y] > a[i][j]) x = i,y = j; } }}int main(){ READ("in.txt"); while(scanf("%lld%lld",&n,&m)!=EOF){ sum = 0; rep(i,1,n){ rep(j,1,m){ scanf("%lld",&a[i][j]); sum += a[i][j]; } } if(n & 1 || m & 1){ printf("%lld\n", sum); if(n & 1){ rep(i,1,n){ rep(j,1,m-1){ if(i & 1) printf("R"); else printf("L"); } if(i < n) printf("D"); else printf("\n"); } }else{ rep(i,1,m){ rep(j,1,n-1){ if(i & 1) printf("D"); else printf("U"); } if(i < m) printf("R"); else printf("\n"); } } }else{ get(); printf("%lld\n",sum - a[x][y]); for(int i = 1; i <= n ;i += 2){ if(x == i || x == i + 1){ rep(j,1,y-1){ if(j & 1) printf("D"); else printf("U"); printf("R"); } if(y < m) printf("R"); rep(j,y+1,m){ if(j & 1 )printf("U"); else printf("D"); if(j < m) printf("R"); } if(i < n - 1) printf("D"); }else if( i < x ){ rep(j,1,m-1) printf("R"); printf("D"); rep(j,1,m-1) printf("L"); printf("D"); }else{ rep(j,1,m-1) printf("L"); printf("D"); rep(j,1,m-1) printf("R"); if(i < n - 1) printf("D"); } } printf("\n"); } } return 0;}
0 0
- HDU 5402 (构造题)Travelling Salesman Problem
- 【HDU 5402】Travelling Salesman Problem(构造)
- hdu 5402 Travelling Salesman Problem (构造)
- hdu 5402 Travelling Salesman Problem 模拟构造
- hdu 5402 Travelling Salesman Problem(构造)
- hdu 5402 Travelling Salesman Problem(构造+模拟)
- HDU 5402 Travelling Salesman Problem (构造)(好题)
- HDU 5402 Travelling Salesman Problem
- HDU 5402 Travelling Salesman Problem
- hdu 5402 Travelling Salesman Problem
- hdu 5402 Travelling Salesman Problem
- hdu 5402 Travelling Salesman Problem
- HDU 5402 Travelling Salesman Problem(棋盘染色 构造 多校啊)
- hdu 5402 Travelling Salesman Problem(构造+棋盘黑白染色)
- HDU 5402 Travelling Salesman Problem(组合数学+构造)
- hdu(5402)——Travelling Salesman Problem(模拟题)
- Travelling Salesman Problem (hdu 5402 模拟)
- HDU-5402 Travelling Salesman Problem(模拟)
- 2015 7 3 java核心技术卷一 7-10章 图形,事件处理,Swing组件和应用程序部署
- Linux下Sublime安装
- spmio内网源部署
- 【GDOI 2013模拟】总结
- JAVA中实现加法器
- HDU 5402 (构造题)Travelling Salesman Problem
- iOS学习(项目中遇到的错误1)
- UIP协议栈三
- App工程结构搭建:几种常见Android代码架构分析
- LeetCode 26 Remove Duplicates from Sorted Array
- HTTP状态码
- 面试题总结
- UIP协议栈四
- 费用流 poj3422 Kaka's Matrix Travels