摘要:
http://wikioi.com/problem/1063/这题是贪心+堆。主要想练习一下堆的写法。算法导论里的方法名是heapify()等,但大家经常用更直观的down(), up()方法(向上,下调整),根据这两个方法,可以有build,insert,getmin方法。向下调整的代码稍微需要判断一下左右子树是否越界,其他都很简单。#include using namespace std;#define LEN 10005int num[LEN];int size;void swap(int a, int b) { int tmp = num[a]; num[a] = num[... 阅读全文
摘要:
一开始看到题还以为要DFS还是BFS,后来发现完全不用。排个序,然后看看大小王能不能弥补缺口就行,但后来又发现还要排除有相同大小牌的情况。#include #include #include using namespace std; int main() { int n; while (cin >> n && n != 0) { vector cards; int kingCount = 0; while (n--) { int x; cin >> x; if (x == 0... 阅读全文
摘要:
用一个栈辅助,模拟过程+判断就可以了。#include #include #include #define LEN 100005using namespace std;int A[LEN];int B[LEN];int main(){ int n; while (cin >> n) { for (int i = 0; i > A[i]; } for (int i = 0; i > B[i]; } stack st; int i = 0; int j = 0; whi... 阅读全文
摘要:
找到以后要再扫一遍确认。http://zhedahht.blog.163.com/blog/static/25411174201085114733349/#include #include #define LEN 100005#define ulong unsigned long longusing namespace std;ulong A[LEN];int main(){ int n; while (cin >> n) { for (int i = 0; i > A[i]; } int count = 0; ulon... 阅读全文