- 浏览: 118409 次
- 性别:
- 来自: 北京
最新评论
写代码最重要的是清晰,包括思路的清晰和代码结构的清晰。我们无法保证写的代码一定是正确的,但我们可以保证自己是在头脑清晰的情况下书写,并且通过不断的练习,用更加清晰的代码结构实现。越清晰,程序就越可能正确,并且即使出错也很容易看到问题。
0) 在能过题的情况下,最朴素最好写的方式就是最好的。 1) double x = 0; scanf("%lf", x); // &x printf("%lf\n", x); // output double -> %f printf("%.6f\n", 0); // undef // best practice printf("%.4f\n", x + EPS); 2) int a[10]; sizeof(a); // 10 * 4 void gao(int a[]) { memset(a, 0xff, sizeof(a)); // sizeof(a) == 4 // best practice fill(a, a + 10, -1); } 3) const int inf = 0x7fffffff; void dijkstra(int dist[], int n) { fill(dist, dist + n, inf); // when a + b will get overflow // best practice fill(dist, dist + n, 0x3f3f3f3f); ... } 4) // output % printf("%%"); // output hex, oct print("%x%o", a, b); 5) int a = 3; if (a = 3) { // == } 6) int x = -7, m = 3; printf("%d\n", x % m); // best practice printf("%d\n", (x % m + m) % m); 7) long long a = 1 << 40; // best practice long long a = 1LL << 40; 8) long long a; printf("%I64d\n", a); // under windows printf("%lld\n", a); // under linux 9) int main() { int a[10 * 1000 * 1000]; // too large in stack ... } // best practice int a[10 * 1000 * 1000]; int main() { ... } // or int main() { vector<int> a; ... } 10) char a[11]; gets(a); // unsafe // best practice fgets(a, 11, stdin); 11) double a = 1.0, b = 1.0 / 888888888888888888 * 888888888888888888; printf("%s\n", a == b ? "same" : "diff"); // best practice int sgn(double x, double eps = 1.0e-9) { return (x > eps) - (x < -eps); } printf("%s\n", sgn(a - b) == 0 ? "same" : "diff"); 12) // round up (int)(a + EPS) (int)(a + EPS + 0.5) 13) // small heap priority_queue< double, vector<double>, greater<double> > que; // unique vector<int> vec; sort(vec.begin(), vec.end()); vec.resize(unique(vec.begin(), vec.end()) – vec.begin()); 14) 总是用cerr输出调试信息,这样在注释调试信息时,搜索cerr就可以很容易注释掉全部的调试信息。 15) CodeBlocks在运行窗口粘贴数据的方法 16) 总是使用fill_n函数 http://www.cplusplus.com/reference/algorithm/fill_n/
发表评论
-
lower_bound and upper_bound
2012-02-09 00:36 1152/** * @brief Finds the ... -
HDU 3954
2012-02-05 10:43 840线段树变种,也是在2logn段上面做文章 /* * ... -
HDU 4027
2012-02-04 22:09 850线段树变种 在2logn段上面做文章,swap(x, y)太阴 ... -
[转载]TopCoder插件
2011-09-08 22:13 972转载自:http://acm.cugb.edu.cn/blog ... -
UVALive 5112 - Sales Prediction
2011-01-06 10:19 1188封装了矩阵类 比赛做得很郁闷,为什么别人写得很长、很罗嗦的代码 ... -
hdu 3236
2010-12-12 14:10 798终于能过这道题了,算是背包必做题之一吧 /* * Au ... -
pku 1018
2010-12-11 15:18 602写了两三个版本,最后这个效率最高 #include < ... -
布斯(Booth)乘法
2010-10-07 19:59 1138源自http://watashi.ws/blog/1515/z ... -
高斯消元
2010-10-07 14:18 804import java.util.*; import j ... -
整数划分
2010-10-07 10:38 840#include <cstdio> #inc ... -
Treap
2010-09-18 22:19 980// Treap // Tested: bjtu1057 ... -
矩阵快速幂
2010-09-18 14:24 1050typedef LL matrix[55][55]; ... -
maximum clique 最大团
2010-09-02 18:12 1134最大团模板 #include <cstdio> ... -
计算Jacobi符号
2010-08-31 13:15 1292Quadratic reciprocity The Jacob ... -
Java 高效I/O
2010-08-19 16:54 775static BufferedReader cin = ... -
DLX pku 3076
2010-08-11 23:45 878标准数独,精确覆盖 // pku3076.cpp #in ... -
DLX hust 1017
2010-08-11 16:50 848“精确覆盖”问题 #include <cstdio& ... -
DLX hdu 3498
2010-08-11 16:48 1041“多重覆盖”或“重复覆盖”问题 #include < ... -
hdu 3509
2010-08-09 11:22 1004推导公式的题目,矩阵幂关键就在于构造系数矩阵 备忘: S(n, ... -
RMQ模板
2010-07-28 11:04 1187/* * Author: rush * Creat ...
相关推荐
KUT-PG ICPC 存储库 这个存储库是什么? 这是“”编程圈“ ”解决编程竞赛“ ”问题并发布答案的知识库。 已上传 KUT-PG 成员和顾问教师使用 C/C++/Java 解决的答案。 什么是 KUT-PG? 这是高知工业大学的官方圈子...
icpc 基础,推荐一下!
acm icpc
2020第45届ICPC济南站题目和解析
ICPC中国大陆区域赛真题训练.pdf
acm 模板 算法 icpc 用于比赛模板下载,很全
ICPC2023 西安区域赛 题解.pdf
ICPC2013 WF 试题, pdf格式
2019年icpc台湾赛区模拟题 2019 ICPC Taiwan Online Programming Contest - Practice Session
icpc2014(英文),2014icpc决赛题!
ACM-ICPC 历年竞赛 真题,各大赛区真题详解,内含几大赛区各年度的真题
基于C++的ACM-ICPC模板
2015 ICPC 长春pdf
历届acm icpc试题.rar
international collegiate programming contest ASIA REGIONALCONTEST ICPC JAKARTA 2019
ACM/ICPC大赛
ACM国际大学生程序设计竞赛(ICPC)是全球范围内最具影响力和声誉的大学生程序设计竞赛之一。参加ICPC对学生和计算机科学领域有着重要的学习意义和影响。 ICPC竞赛对学生的学习意义和影响非常重大。它不仅提高了...
2019icpc首尔网络赛 2019-10-5 2019 Asia Regional - Seoul - Nationwide Internet Competition
本资源为2022年 ACM ICPC程序设计竞赛沈阳站的正式赛题目,比赛时长一共五小时,题目为全英文题目,并且在比赛的时候可以使用一切纸质书籍,但禁止使用电子产品,一组三个队员,只允许使用一台电脑,不过可以配备...
ACM_ICPC在线评测系统_OJ,教你实现评测的过程