《算法竞赛入门经典(大白书)》1.2 && 1.3 【待续】
2017-11-08 14:50
148 查看
uva 11462 - Age Sort
题意:
给你最多2000000个数据,大小是1到99的数,让你排序输出。
思路:
对于内存的限制,所以我们考虑不开数组记录所有数字,而是选择用1到99每个数字出现了多少次。
uva 11078 - Open Credit System
题意:
给出n个数,找出两个数之间差的最大值,要求num[i] - num[j](i < j)
思路:
仔细思考一下,其实只需要枚举j,并在过程中保存j的最小值即可。
题意:
给你最多2000000个数据,大小是1到99的数,让你排序输出。
思路:
对于内存的限制,所以我们考虑不开数组记录所有数字,而是选择用1到99每个数字出现了多少次。
#include <stdio.h> #include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int maxn = 5000 + 5; const int INF = 0x3f3f3f3f; typedef long long LL; typedef pair<int, int>pii; typedef pair<double, double>pdd; typedef pair<LL, LL>pLL; typedef unsigned long long ull; int age[105]; int main() { int n; while(~scanf("%d", &n)) { if(n == 0) break; memset(age, 0, sizeof(age)); for(int i = 0; i < n; i++) { int x; scanf("%d", &x); age[x]++; } int cnt = 0; for(int i = 1; i <= 100; i++) { while(age[i]--) printf("%d%c", i, ++cnt == n ? '\n' : ' '); } } return 0; }
uva 11078 - Open Credit System
题意:
给出n个数,找出两个数之间差的最大值,要求num[i] - num[j](i < j)
思路:
仔细思考一下,其实只需要枚举j,并在过程中保存j的最小值即可。
#include <stdio.h> #include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int maxn = 100000 + 5; const int INF = 0x3f3f3f3f; typedef long long LL; typedef pair<int, int>pii; typedef pair<double, double>pdd; typedef pair<LL, LL>pLL; typedef unsigned long long ull; int a[maxn]; int main() { int T; scanf("%d", &T); while(T--) { int n; scanf("%d", &n); for(int i = 0; i < n; i++) scanf("%d", &a[i]); int ans = -INF, maxx = a[0]; for(int j = 1; j < n; j++) { ans = max(ans, maxx - a[j]); maxx = max(maxx, a[j]); } printf("%d\n", ans); } return 0; }
相关文章推荐
- 《算法竞赛入门经典(大白书)》1.1 【待续】
- 1.2编写C++应用程序&1.3学习桌面应用程序的编程
- java错误ERROR: JDWP Unable to get JNI 1.2 environment, jvm->GetEnv() return code = -2
- Tomcat version 6.0 only supports J2EE 1.2, 1.3, 1.4, and Java EE 5 Web modules
- Android大环境杂谈<待续中>
- 1.3--Jsp学习之EL&JSTL
- Tomcat version 6.0 only supports J2EE 1.2, 1.3, 1.4, and Java EE 5 Web modules
- 1.1学习之初1.2约定1.3认识Linux1.4创建虚拟机1.5安装CentOS7
- ERROR: JDWP Unable to get JNI 1.2 environment, jvm->GetEnv() return code = -2
- Tomcat version 6.0 only supports J2EE 1.2, 1.3, 1.4, and Java EE 5 Web modules
- Tomcat version 6.0 only supports J2EE 1.2, 1.3, 1.4, and Java EE 5 Web modules
- atitit 技术选型之道. attilax著 艾龙著 1. 标准 2 1.1. 符合趋势度 2 1.2. 简单易用 2 1.3. 文档丰富度 2 1.4. 下载便利性 2 1.5. 性能 2 1.
- 游戏UI设计(1.2)--Textures & Sprite之封装
- Script Browser & Script Analyzer 1.3更新发布
- Tomcat version 6.0 only supports J2EE 1.2, 1.3, 1.4, and Java EE 5 Web modules
- Tomcat version 6.0 only supports J2EE 1.2, 1.3, 1.4, and Java EE 5
- SharePoint Server 2007 SDK1.3 & WSS 3.0 SDK 1.3
- Tomcat version 6.0 only supports J2EE 1.2, 1.3, 1.4, and Java EE 5 Web modules