diff --git a/GESP/NoBreak.cpp b/GESP/NoBreak.cpp new file mode 100644 index 0000000..1fac6df --- /dev/null +++ b/GESP/NoBreak.cpp @@ -0,0 +1,33 @@ +#include +using namespace std; +// C++入门经典-例3.13-不加break的switch判断语句 +// https://blog.csdn.net/lovemi93/article/details/90702825 + +int main() { + char c; + while (1) { + cin >> c; + if (c == 'q') break; + + switch (c) { + case 'A': + cout << "1 "; + break; + case 'B': + cout << "3 "; + case 'C': + cout << "3 "; + case 'D': + cout << "Here!"; + cout << "5 "; + break; + case 'E': + cout << "5 "; + break; + default: + cout << "9 " << endl; + } + cout << endl; + } + return 0; +} \ No newline at end of file diff --git a/TangDou/AcWing/MinimalPath/920.cpp b/TangDou/AcWing/MinimalPath/920.cpp index 5d23372..6af0e6c 100644 --- a/TangDou/AcWing/MinimalPath/920.cpp +++ b/TangDou/AcWing/MinimalPath/920.cpp @@ -5,12 +5,12 @@ const int INF = 0x3f3f3f3f; typedef pair PII; const int N = 1e5 + 10; -const int M = 2 * N; +const int M = N * 2; int n; // 总共有N个车站 int m; // 开通了M条单程巴士线路 int h[N], e[M], w[M], ne[M], idx; -int dist[N]; // 最小距离数组 +int dis[N]; // 最小距离数组 int stop[N]; // 站点数组 bool st[N]; // 是否在队列中 @@ -19,8 +19,8 @@ void add(int a, int b, int c) { } // 求1号点到n号点的最短路距离,如果从1号点无法走到n号点则返回-1 void dijkstra() { - memset(dist, 0x3f, sizeof dist); // 求最小设最大 - dist[1] = 0; // 1到自己,乘车数0 + memset(dis, 0x3f, sizeof dis); // 求最小设最大 + dis[1] = 0; // 1到自己,乘车数0 priority_queue, greater> q; // 小顶堆 q.push({0, 1}); // 1号入队列 @@ -28,14 +28,14 @@ void dijkstra() { auto t = q.top(); q.pop(); int u = t.second; - int d = t.first; // 此处 d=t.first没有用上,经测试,其实d=dist[u],用哪个都是一样的 + // int d = t.first; // 此处 d=t.first没有用上,经测试,其实d=dis[u],用哪个都是一样的 if (st[u]) continue; st[u] = true; for (int i = h[u]; ~i; i = ne[i]) { int v = e[i]; - if (dist[v] > dist[u] + w[i]) { - dist[v] = dist[u] + w[i]; - q.push({dist[v], v}); + if (dis[v] > dis[u] + w[i]) { + dis[v] = dis[u] + w[i]; + q.push({dis[v], v}); } } } @@ -43,16 +43,16 @@ void dijkstra() { int main() { memset(h, -1, sizeof h); // 初始化邻接表 - scanf("%d%d", &m, &n); // 总共有N个车站,开通了M条单程巴士线路 + cin >> m >> n; // 总共有N个车站,开通了M条单程巴士线路 while (m--) { // m条边 // ① 先读入第一个数字 int cnt = 0; // cnt一定要清零 - scanf("%d", &stop[++cnt]); + cin >> stop[++cnt]; char ch = getchar(); while (ch == ' ') { // ② 读入其它数字 - scanf("%d", &stop[++cnt]); // 还有就继续读 - ch = getchar(); // 为下一次做准备 + cin >> stop[++cnt]; // 还有就继续读 + ch = getchar(); // 为下一次做准备 } // 这个建图建的妙啊! // 通过多条边,成功映射了问题,将一趟车问题转化为多个点之间边是1问题 @@ -62,9 +62,9 @@ int main() { } dijkstra(); - if (dist[n] == INF) + if (dis[n] == INF) puts("NO"); else - printf("%d\n", dist[n] - 1); + printf("%d\n", dis[n] - 1); return 0; } \ No newline at end of file diff --git a/TangDou/AcWing/Test/796.cpp b/TangDou/AcWing/Test/796.cpp new file mode 100644 index 0000000..4e5d998 --- /dev/null +++ b/TangDou/AcWing/Test/796.cpp @@ -0,0 +1,36 @@ +#include +using namespace std; +const int N = 1010; +int a[N][N]; +int s[N][N]; + +int main() { + int n, m, q; + cin >> n >> m >> q; + for (int i = 1; i <= n; i++) + for (int j = 1; j <= m; j++) { + cin >> a[i][j]; + s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + a[i][j]; + } + + while (q--) { + int x1, y1, x2, y2; + cin >> x1 >> y1 >> x2 >> y2; + printf("%d\n", s[x2][y2] - s[x1 - 1][y2] - s[x2][y1 - 1] + s[x1 - 1][y1 - 1]); + } + return 0; +/* +输入样例: +3 4 3 +1 7 2 4 +3 6 2 8 +2 1 2 3 +1 1 2 2 +2 1 3 4 +1 3 3 4 +输出样例: +17 +27 +21 + */ +} diff --git a/TangDou/LuoGuBook/P2615.cpp b/TangDou/LuoGuBook/P2615.cpp index da53ea9..b085a9c 100644 --- a/TangDou/LuoGuBook/P2615.cpp +++ b/TangDou/LuoGuBook/P2615.cpp @@ -6,7 +6,7 @@ int n; int g[N][N]; int main() { - scanf("%d", &n); + cin >> n; int r = 1; int c = n / 2 + 1; g[r][c] = 1;