↓ 跳过正文
  1. Posts/

poj 1350 Cabric Number Problem

·422 字·1 分钟

http://poj.org/problem?id=1350

题意:6174问题。。。一个四位数。。四个数字重排。。。最大的减去最小的得到新的数字。最后一定能得到6174或者0.除非这个四位数的四个数字都一样。写出变化的过程。

思路:。。。可能不是不四位数。。略坑。然后写了下字符串和数字相互转化的两个函数。嗯。

代码实现
 1/* ***********************************************
 2Author :111qqz
 3Created Time :2016年01月20日 星期三 12时51分41秒
 4File Name :code/poj/1350.cpp
 5************************************************ */
 6
 7#include <cstdio>
 8#include <cstring>
 9#include <iostream>
10#include <algorithm>
11#include <vector>
12#include <queue>
13#include <set>
14#include <map>
15#include <string>
16#include <cmath>
17#include <cstdlib>
18#include <ctime>
19#define fst first
20#define sec second
21#define lson l,m,rt<<1
22#define rson m+1,r,rt<<1|1
23#define ms(a,x) memset(a,x,sizeof(a))
24typedef long long LL;
25#define pi pair < int ,int >
26#define MP make_pair
27
28using namespace std;
29const double eps = 1E-8;
30const int dx4[4]={1,0,0,-1};
31const int dy4[4]={0,-1,1,0};
32const int inf = 0x3f3f3f3f;
33int n;
34int cnt;
35
36int get_next( int x)
37{
38    int a,b,len;
39    char st[10];
40    sprintf(st,"%d",x);
41    len = strlen(st);
42//    if (len<4) return -1;
43    if (st[0]==st[1]&&st[1]==st[2]&&st[2]==st[3]&&st[3]==st[0]) return -1;
44    for ( int i = 0 ; i < len ; i++)
45	for ( int j =  i+1 ;  j < len ; j++)
46	    if (st[i]<st[j]) swap(st[i],st[j]);
47
48    sscanf(st,"%d",&a);
49//    cout<<st<<endl;
50
51    for ( int i = 0 ;i < len/2 ;  i++) swap(st[i],st[len-1-i]);
52  //  cout<<st<<endl;
53
54    sscanf(st,"%d",&b);
55
56    printf("%d-%d=%d\n",a,b,a-b);
57    return a-b;
58
59
60}
61int main()
62{
63	#ifndef  ONLINE_JUDGE
64	freopen("code/in.txt","r",stdin);
65  #endif
66
67	while (scanf("%d",&n)!=EOF&&n!=-1)
68	{
69	    cnt =  0 ;
70	    printf("N=%d:\n",n);
71	    if (n<1000||n>9999)
72	    {
73		puts("No!!");
74		continue;
75	    }
76	    while (1)
77	    {
78		cnt++;
79		n = get_next(n);
80	//	cout<<"n:"<<n<<endl;
81		if (n==-1)
82		{
83		    puts("No!!");
84		    break;
85		}
86		if (n==0||n==6174)
87		{
88		    printf("Ok!! %d times\n",cnt);
89		    break;
90		}
91	    }
92	}
93
94  #ifndef ONLINE_JUDGE
95  fclose(stdin);
96  #endif
97    return 0;
98}

相关文章

hdoj 5606 ||bc #68 div 2 B tree

·596 字·2 分钟
http://acm.hdu.edu.cn/showproblem.php?pid=5606 题意:一棵树,边权为0或者1,问对于每个点,距离它最近的点(包括自身)的个数是多少。输出将所有点的答案异或后的值。 思路:由于包括自身,自己与自己距离为0,那么最近的点一定也距离为0,所以就是找对于每个点与它相连的边权为0 的点的个数**。建图的时候可以不管边权为1的点。。因为这样的点不会对任何点的答案有贡献。**正解貌似是冰茶几。。我就是dfs搞了下。。找到每一个联通快的点数。。然后把某个联通快的所有点的答案都更新成点的个数。。。

hdoj 5605 || bc #68 div 2 1001 geometry

·324 字·1 分钟
题意:geometry Accepts: 324 Submissions: 622 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) 问题描述 在平面直角坐标系上有一个点PP, 他的坐标是(x, y)(x,y). 有一条直线y = kx + by=kx+b经过了PP, 且分别交x, yx,y正半轴于A, BA,B. 求|PA| * |PB|∣PA∣∗∣PB∣的最小值. 输入描述 第一行一个TT, 表示数据组数. 接下来TT行每行两个正整数x,yx,y, 表示PP的坐标.

codeforces goodbye 2015 A. New Year and Days

·192 字·1 分钟
http://codeforces.com/contest/611/problem/A 题意:两种查询,一种是 x of week,x为1.。7,对应输出2016年星期x有多少天。另一种为x of month ,对应输出2016年至少有x天的月份有多少天。 思路:直接搞。。。。竟然脑残被hack了。。。sad.

cf 611 B ||codeforces goodbye 2015 B. New Year and Old Property (数学或者数位dp)

·730 字·2 分钟
http://codeforces.com/contest/611/problem/B 题意:问a到b(1E18),二进制表示中只有一个0的数有多少个。 思路:这么大的数。。。不是有循环节就是math problems. UD:20160318讲道理还有可能是数位dp好不好。。。 我们发现可以很容易得算出1到x的二进制表示中只有一个0 的数有多少个。

cf 611 A||codeforces goodbye 2015 C. New Year and Domino

·465 字·1 分钟
http://codeforces.com/contest/611/problem/C 题意:给出一个n*m的地图,.表示可以空,#表示墙。一个东西需要占两个相邻的格子,问给定一个矩形,放一个东西的方案数。 思路:q很大。。应该是先预处理出来直接调用答案。。。计数问题累加性。。应该是前缀和之类。。需要做的就是怎么标记。。我的做法是竖着放和横着放的个数分开来存。从左往右从上往下,每次标记到后一个点。然后二维的前缀和。然后每次询问的时候,去掉最上边和最左边两条边界上对应的多加的点。