摘要:
题目大意:给出一些原料和价钱和若干份菜谱,每份菜谱都标明所需的原料和数量,找出所有不超过预算的菜谱。 没什么好说的,主要是对map的运用。 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 using namespace std; 8 typedef map msi; 9 10 struct Recipe11 {12 string name;13 int cost;14 bool operator > T;28 getchar();29 msi ing... 阅读全文
posted @ 2013-08-31 21:41
xiaobaibuhei
阅读(319)
评论(0)
推荐(0)
摘要:
题目大意:给一个中缀表达式,转换成后缀表达式。 这类题一直不太会,让我想就是建一棵表达式树,然后后续遍历算了,可是建树的过程实在太麻烦了。今天才看到有中缀表达式转换成后缀表达式的算法,可以用栈进行实现,我现在才知道...算法如下: 这里假定操作数均为一位数字,操作符只有(、)、+、-、*和/,结果保存到postfix数组里,还要用到一个栈来保存运算符。 从左向右扫描表达式,如果当前字符为: (1)数字,将该数字添加到postfix末尾。 (2)(,将(压入栈中。 (3)),如果当前栈顶元算不是(,将栈中的运算符逐个弹出并追加到postfix末尾,知道栈顶为(,弹出但不追加。 ... 阅读全文
posted @ 2013-08-31 17:41
xiaobaibuhei
阅读(474)
评论(0)
推荐(0)
摘要:
题目大意:给一个有n个数的序列,通过交换相邻的逆序数使这个序列最终有序,求需要交换的次数。 本来可以用冒泡排序解决,但是n达到105,用冒泡排序会超时,用O(nlogn)的归并排序可以达到要求。《算法竞赛入门经典》第八章的“逆序对数”有详细介绍。 1 #include 2 #define MAXN 100000+10 3 4 int a[MAXN], tmp[MAXN]; 5 int cnt; 6 7 void merge_sort(int l, int r) 8 { 9 if (r-l == 1) return;10 int mid = l + (r-l)/2;... 阅读全文
posted @ 2013-08-31 15:02
xiaobaibuhei
阅读(258)
评论(0)
推荐(0)
摘要:
题目大意:给n个数的一个序列,通过交换相邻的两个数使得这n个数按照从小到大的顺序排列。 Inversion index problem: count how many swaps are needed to make the list sorted. 使用冒泡排序解决。 1 #include 2 3 int main() 4 { 5 #ifdef LOCAL 6 freopen("in", "r", stdin); 7 #endif 8 int T; 9 scanf("%d", &T);10 int a[60];11 whil 阅读全文
posted @ 2013-08-31 13:02
xiaobaibuhei
阅读(219)
评论(0)
推荐(0)

浙公网安备 33010602011771号