1.二维数组偏移量读入
int a[1003][1003]; scanf("%d",&a[i][j]); = scanf("%d",a[i]+j);
2.读取无用字符
scanf("%*c%*c");
3.unique函数,用于去重。见www.cnblogs.com/hua-dong/p/7943983.html
4.vector数组下标默认从零开始!!!
5.priority_queue的自定义使用(例如堆优化Dijkstra)https://www.cnblogs.com/cielosun/p/5654595.html
1 //FROM : https://www.cnblogs.com/cielosun/p/5654595.html 2 int cost[MAX_V][MAX_V]; 3 int d[MAX_V], V, s; 4 //自定义优先队列less比较函数 5 struct cmp 6 { 7 bool operator()(int &a, int &b) const 8 { 9 //因为优先出列判定为!cmp,所以反向定义实现最小值优先 10 return d[a] > d[b]; 11 } 12 }; 13 void Dijkstra() 14 { 15 std::priority_queue<int, std::vector<int>, cmp> pq; 16 pq.push(s); 17 d[s] = 0; 18 while (!pq.empty()) 19 { 20 int tmp = pq.top();pq.pop(); 21 for (int i = 0;i < V;++i) 22 { 23 if (d[i] > d[tmp] + cost[tmp][i]) 24 { 25 d[i] = d[tmp] + cost[tmp][i]; 26 pq.push(i); 27 } 28 } 29 } 30 }