↓ Skip to main content
  1. Posts/

hdu 3183 A Magic Lamp ( 暴力)

·455 words·1 min
Note: This article is available in Chinese only. 本文暂无英文版本。 View original

hdu3183题目链接

题意:n位长的数字串(n<=1000),删掉m个(m<=n),使得剩下的数字串表示的数字最小。 忽略前导0.

思路:暴力搞就可以。要注意每位数字是有一定位置的范围的。比如当前是第i位数字,后面还要取n-m-i位数字,那么第i位数字最多只能取到第k位,k=m+i,因为这样才能保证后面还有n-m-i位数字。

代码实现
 1/* ***********************************************
 2Author :111qqz
 3Created Time :2016年05月16日 星期一 13时15分44秒
 4File Name :code/hdu/3183.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;
33const int N=1E3+7;
34int n,m;
35
36int ans[N];
37char st[N];
38int main()
39{
40	#ifndef  ONLINE_JUDGE
41	freopen("code/in.txt","r",stdin);
42  #endif
43
44	while (~scanf("%s %d",st,&m))
45	{
46	    n = strlen(st);
47	    ms(ans,0);
48
49	    int x = 0 ;
50	    for ( int i = 1 ; i <= n-m ; i++)
51	    {
52		int MIN = inf;
53		for ( int j = x+1 ; j <= m+i ; j++)
54		{
55		    int val = st[j-1]-'0';
56		    if (val<MIN)
57		    {
58			MIN = val;
59			x = j;
60		    }
61		}
62		ans[i] = MIN;
63	    }
64
65
66	    bool zero = true;
67	    bool output = false;
68	    for ( int i = 1; i <= n-m ; i++)
69	    {
70		if (ans[i]!=0) zero = false;
71		if (!zero)
72		{
73		    output = true;
74		    printf("%d",ans[i]);
75		}
76	    }
77	    if (output)
78	    printf("\n");
79	    else printf("0\n");
80
81	}
82
83
84
85  #ifndef ONLINE_JUDGE
86  fclose(stdin);
87  #endif
88    return 0;
89}

Related

BZOJ 1653: [Usaco2006 Feb]Backward Digit Sums(暴力)

·560 words·2 mins
1653: [Usaco2006 Feb]Backward Digit Sums # Time Limit: 5 Sec Memory Limit: 64 MB Submit: 349 Solved: 258 [Submit][Status][Discuss] Description # FJ and his cows enjoy playing a mental game. They write down the numbers from 1 to N (1 <= N <= 10) in a certain order and then sum adjacent numbers to produce a new list with one fewer number. They repeat this until only a single number is left. For example, one instance of the game (when N=4) might go like this: 3 1 2 4 4 3 6 7 9 16 Behind FJ’s back, the cows have started playing a more difficult game, in which they try to determine the starting sequence from only the final total and the number N. Unfortunately, the game is a bit above FJ’s mental arithmetic capabilities. Write a program to help FJ play the game and keep up with the cows.

BZOJ 1622: [Usaco2008 Open]Word Power 名字的能量 (暴力)

·808 words·2 mins
1622: [Usaco2008 Open]Word Power 名字的能量 # Time Limit: 5 Sec Memory Limit: 64 MB Submit: 462 Solved: 228 [Submit][Status][Discuss] Description # 约翰想要计算他那N(1≤N≤1000)只奶牛的名字的能量.每只奶牛的名字由不超过1000个字待构成,没有一个名字是空字体串, 约翰有一张“能量字符串表”,上面有M(1≤M≤100)个代表能量的字符串.每个字符串由不超过30个字体构成,同样不存在空字符串.一个奶牛的名字蕴含多少个能量字符串,这个名字就有多少能量.所谓“蕴含”,是指某个能量字符串的所有字符都在名字串中按顺序出现(不一定一个紧接着一个). 所有的大写字母和小写字母都是等价的.比如,在贝茜的名字“Bessie”里,蕴含有“Be” “sI”“EE”以及“Es”等等字符串,但不蕴含“lS”或“eB”.请帮约翰计算他的奶牛的名字的能量.

bzoj 1599: [Usaco2008 Oct]笨重的石子 (暴力)

·624 words·2 mins
1599: [Usaco2008 Oct]笨重的石子 # Time Limit: 10 Sec Memory Limit: 162 MB Submit: 886 Solved: 614 [Submit][Status][Discuss] Description # 贝西喜欢棋盘游戏和角色扮演类游戏所以她说服Farmer John把她带到玩具店,在那里,她购买了三个不同的骰子,这三个质量均匀的骰子,分别有S1,S2,S3个面。(2 <= S1 <= 20; 2 <= S2 <= 20; 2 <= S3 <= 40). 贝西掷啊掷啊掷啊,想要知道出现几率最大的和是多少。 问题给出三个骰子的面数,让你求出出现几率最大的和是多少。如果有很多种和出现的几率相同,那么就输出小的那一个。

codeforces #346 div 2 C. Tanya and Toys (暴力乱搞)

·613 words·2 mins
题目链接 题意:有1E9个礼物,第i个礼物价钱是i,然后现在已经有n个不重复的礼物,a[i],m元钱,想尽可能多得买不同种类的礼物,还能买多少个。 思路:先不考虑已经买的,从1连续买到k,然后考虑在这个区间内已经买的,等于实际上没有花钱。 反正就是暴力搞啊搞啊。。我也不知道怎么搞。。 结果最后。。方案数为0的时候。。。最后一个答案我是单独输出的。。忘了判断了。。。所以会输出两个0.宝宝心里苦啊。。。。。。。。

codeforces 334 B. Eight Point Sets (暴力)

·188 words·1 min
题目链接 题意:给出8个点,问能否构成一个8元素集合,使得x1/* *********************************************** Author :111qqz Created Time :2016年03月31日 星期四 13时39分27秒 File Name :code/cf/problem/334B.cpp ************************************************ */ #include #include #include #include #include #include #include #include #include #include #include #include #define fst first #define sec second #define lson l,m,rt«1 #define rson m+1,r,rt«1|1 #define ms(a,x) memset(a,x,sizeof(a)) typedef long long LL; #define pi pair < int ,int > #define MP make_pair