int f(int x = 2){ return x * 3; } int main(){ cout << f() << " " << f(4); }
int main() { int a = 5; int* p = &a; int** q = &p; **q += 7; cout << a << " " << *p; }
int a[3][4] = { {1,2,3,4}, {5,6,7,8}, {9,10,11,12} }; int (*p)[4] = a;
void fun(int a, int &b, int *c){ a += 1; b += 2; *c += 3; } int main(){ int x = 1, y = 1, z = 1; fun(x, y, &z); cout << x << " " << y << " " << z; }
int x = 3; void f(int& x){ x += 2; } int main(){ int x = 10; f(x); cout << x << " " << ::x; }
struct S { int a; int b; }; void g(S s){ s.a += 10; } void h(S& s){ s.b += 10; } int main(){ S s{1,2}; g(s); h(s); cout << s.a << " " << s.b; }
int climb(int n){ if(n <= 2) return n; int a = 1, b = 2, c = 0; for(int i = 3; i <= n; i++){ c = a + b; a = b; b = c; } return c; }
void ins(int a[], int n){ for(int i = 1; i < n; i++){ int key = a[i]; int j = i-1; while(j >= 0 && __________){ a[j+1] = a[j]; j--; } a[j+1] = key; } }
int cnt=0; for(int i=0; i<n; i++){ for(int j=0; j<n; j++){ if( (i+j) % 3 == 0) cnt++; } }
int divi(int a,int b){ if(b==0) throw 0; return a/b; } int main(){ try{ cout << divi(10,0); }catch(const char* msg){ cout << "A"; }catch(int){ cout << "B"; } }
struct Player{ int score; }; void up(Player players[], int n, int idx){ Player cur = players[idx]; int i = idx; while( ____________________ ){ players[i] = players[i-1]; i--; } players[i] = cur; }
void add10(int &x) { x += 10; } int main() { int a = 5; add10(a); }
int main() { int a[2][3]; cout << &a[1][2] - &a[0][1] << endl; return 0; }
int calc(int x, int y = 10); int calc(int x) { return x * 2; } int calc(int x, int y) { return x * y; } int main() { cout << calc(5); }
int x = 10; void f() { int x = 20; cout << x; } int main() { f(); cout << x; }
struct GameCharacter { string name; int level; float position_x; float position_y; struct Equipment { string weapon; int attack_bonus; int defense_bonus; } equipment; struct Skill { string name; int damage; } skills[8]; int skill_count; };
ofstream fout("data.txt"); cout << "Hello"; fout.close();
int fib(int n) { if (n <= 1) return n; int f0 = 0, f1 = 1, cur = 0; for (int i = 2; i <= n; i++) { cur = f0 + f1; f0 = f1; f1 = cur; } return cur; }
现有一片山地,可以视为一个 $N$ 行 $M$ 列的网格图,第 $i$行$j$ 列的海拔为 $h_{i,j}$。
如果一个单元格的海拔不高于其所有相邻单元格(相邻包括上、下、左、右、左上、右上、左下、右下,最多 $8$个方向)的海拔,则称该单元格为山谷。
请你数一数该片山地中有多少山谷。
第一行包含 $2$ 个整数 $N,M$,表示山地的大小。
之后$N$行,每行包含 $M$ 个整数 $h_{i,1},h_{i,2},\cdots, h_{i,M}$,表示海拔。
输出 1 行,包含 1 个整数 $C$,表示山谷的数量。
3 5 7 6 6 7 9 6 5 6 7 6 6 5 7 8 9
3
【样例解释】
样例 1 如图所示,绿色单元格代表山谷:
【数据范围】
保证 $1 \le N,M \le 100$,$1 \le h_{i,j} \le 10^5$ 。
商店推出了许多礼盒,每个礼盒中包含 k 件商品,每件商品都有一个价格。
现在需要对这些礼盒进行排序,排序规则如下:
1. 先按礼盒总价格从小到大排序;
2. 如果总价格相同,按礼盒中最贵商品的价格从小到大排序;
3. 如果仍然相同,按礼盒中最便宜商品的价格从小到大排序;
4. 如果仍然相同,按礼盒编号从小到大排序。
请输出排序后的礼盒编号。
第一行包含两个整数 $n$ 和 $k$,分别表示礼盒数量和每个礼盒中商品的数量。
接下来 $n$ 行,每行包含 $k$ 个整数,第 $i$ 行表示第 $i$ 个礼盒中各商品的价格。
输出一行,包含排序后的礼盒编号(编号从 1 开始),用空格分隔。
4 3 3 5 2 4 1 5 2 2 4 3 4 3
3 4 2 1
4 个礼盒分别为:
编号|商品价格|总价|最大值|最小值
--|--|--|--|--
1 |3 5 2| 10 |5 |2
2 |4 1 5| 10 |5 |1
3 |2 2 4| 8 |4 |2
4 |3 4 3| 10 |4 |3
排序过程:
1. 按总价排序,3号礼盒总价最小;
2. 其余总价均为 10,再按最大值排序,4号最大值更小;
3. 1号和2号最大值相同,再按最小值排序,2号更小。
最终顺序为:3 4 2 1
保证 $1 \le n \le 10^3$,$1 \le k \le 10$ ,商品价格 $ \le 10^4$。