暴力 ZOJ 1403 Safecracker

题目传送门

 1 /*
 2     暴力:纯暴力,在家水水
 3 */
 4 #include <cstdio>
 5 #include <cstring>
 6 #include <algorithm>
 7 #include <iostream>
 8 #include <string>
 9 #include <vector>
10 #include <cmath>
11 using namespace std;
12
13 const int MAXN = 1e3 + 10;
14 const int INF = 0x3f3f3f3f;
15 char s[15];
16 int v[15];
17 int len, tar;
18
19 bool cmp(int x, int y)    {return x > y;}
20
21 void work(void)
22 {
23     for (int i=0; i<len; ++i)
24     {
25         for (int j=0; j<len; ++j)
26         {
27             if (i != j)
28             {
29                 for (int k=0; k<len; ++k)
30                 {
31                     if (k != i && k != j)
32                     {
33                         for (int l=0; l<len; ++l)
34                         {
35                             if (l != i && l != j && l != k)
36                             {
37                                 for (int m=0; m<len; ++m)
38                                 {
39                                     if (m != i && m != j && m != k && m != l)
40                                     {
41                                         if (v[i] - pow (v[j], 2) + pow (v[k], 3) - pow (v[l], 4) + pow (v[m], 5) == tar)
42                                         {
43                                             printf ("%c%c%c%c%c\n", v[i] + ‘A‘ - 1, v[j] + ‘A‘ - 1, v[k] + ‘A‘ - 1, v[l] + ‘A‘ - 1, v[m] + ‘A‘ - 1);
44                                             return ;
45                                         }
46                                     }
47                                 }
48                             }
49                         }
50                     }
51                 }
52             }
53         }
54     }
55
56     printf ("no solution\n");
57 }
58
59 int main(void)        //ZOJ 1403 Safecracker
60 {
61 //    freopen ("ZOJ_1403.in", "r", stdin);
62
63     while (scanf ("%d%s", &tar, &s) == 2)
64     {
65         if (tar == 0 && strcmp (s, "END") == 0)    break;
66         len = strlen (s);
67         for (int i=0; i<len; ++i)    v[i] = s[i] - ‘A‘ + 1;
68         sort (v, v+len, cmp);
69
70         work ();
71     }
72
73     return 0;
74 }
75
76
77 /*
78 v - w^2 + x^3 - y^4 + z^5 = target
79 */
时间: 2024-10-06 07:32:46

暴力 ZOJ 1403 Safecracker的相关文章

[数据结构暴力] zoj 3749 Chameleon

题目链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3749 Chameleon Time Limit: 6 Seconds      Memory Limit: 65536 KB Given n groups of integers(all the integers are distinct). You should answer Q queries in this problem. Each query con

ZOJ 1403

Safecracker Time Limit: 2 Seconds      Memory Limit: 65536 KB === Op tech briefing, 2002/11/02 06:42 CST === "The item is locked in a Klein safe behind a painting in the second-floor library. Klein safes are extremely rare; most of them, along with K

zoj题目分类

饮水思源---zoj 转载自:http://bbs.sjtu.edu.cn/bbscon,board,ACMICPC,file,M.1084159773.A.html 注:所有不是太难的题都被归成了“简单题”,等到发现的时候已经太晚了,我太死脑筋 了……:( 有些题的程序我找不到了,555……:( SRbGa的题虽然都很经典……但是由于其中的大部分都是我看了oibh上的解题报告后做 的,所以就不写了…… 题目排列顺序没有规律……:( 按照个人感觉,最短路有的算做了DP,有的算做了图论. 有些比较

POJ百道水题列表

以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight Moves1101 Gamblers1204 Additive equations 1221 Risk1230 Legendary Pokemon1249 Pushing Boxes 1364 Machine Schedule1368 BOAT1406 Jungle Roads1411 Annive

【ZOJ】3785 What day is that day? ——浅谈KMP应用之ACM竞赛中的暴力打表找规律

首先声明一下,这里的规律指的是循环,即找到最小循环周期.这么一说大家心里肯定有数了吧,“不就是next数组性质的应用嘛”. 先来看一道题 ZOJ 3785 What day is that day? Time Limit: 2 Seconds      Memory Limit: 65536 KB It's Saturday today, what day is it after 11 + 22 + 33 + ... + NN days? Input There are multiple tes

hdu 1015 Safecracker (纯暴力)

Safecracker Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 8183    Accepted Submission(s): 4143 Problem Description === Op tech briefing, 2002/11/02 06:42 CST === "The item is locked in a Klein

HDU 1015.Safecracker【暴力枚举】【8月17】

Safecracker Problem Description === Op tech briefing, 2002/11/02 06:42 CST === "The item is locked in a Klein safe behind a painting in the second-floor library. Klein safes are extremely rare; most of them, along with Klein and his factory, were des

HDU-1015 Safecracker(暴力枚举)

题目回顾(HDU-1015) Safecracker Problem Description "The item is locked in a Klein safe behind a painting in the second-floor library. Klein safes are extremely rare; most of them, along with Klein and his factory, were destroyed in World War II. Fortunat

zoj 3818 Pretty Poem(暴力处理字符串)2014年牡丹江赛区网络赛

Pretty Poem Time Limit: 2 Seconds      Memory Limit: 65536 KB Poetry is a form of literature that uses aesthetic and rhythmic qualities of language. There are many famous poets in the contemporary era. It is said that a few ACM-ICPC contestants can e