zoukankan      html  css  js  c++  java
  • 奇怪的代码增加了

    小编原以为自己可以拿到50分的好成绩,结果只拿到了30分,小编当时很疑惑,考后看了很久也没看出来错在了哪里,你看出来了吗?

    	} else {
    		int last = 0, sum = 0;
    		for (register int i = 1; i <= m; i++) {
    			k[i] = read(), v[i] = read();
    			if (k[i] == 1) {
    				last = i;
    				sum = 0;
    			} else {
    				sum += v[i];
    			}
    		}
    		int C, K, V;
    		for (register int i = 1; i <= q; i++) {
    			C = read(), K = read(), V = read();
    			if (C < last) {///在左无影响
    				k[C] = K, v[C] = V;
    				printf ("%d
    ", sum);
    			} else if (C == last && K == '1') {//不变
    				printf ("%d
    ", sum);
    			} else if (C > last && K == '0') {//在右加答案
    				sum += (V - v[C]);
    				k[C] = 0, v[C] = V;
    				printf ("%d
    ", sum);
    			} else if (C == last && K == '0') {//换切点
    				k[C] = 0, v[C] = V;
    				sum += V;
    				for (register int j = last - 1; j >= 1; j--) {
    					if (k[j] == '1') {
    						last = j;
    						break;
    					} else {
    						sum += v[j];
    					}
    				}
    				printf ("%d
    ", sum);
    			} else if (C > last && K == '1') {//
    				sum = 0;
    				k[C] = 1, v[C] = V;
    				for (register int j = m; j >= 1; j--) {
    					if (k[j] == '1') {
    						last = j;
    						break;
    					} else {
    						sum += v[j];
    					}
    				}
    				printf ("%d
    ", sum);
    			}
    		}
    	}
    

    答案揭晓:

    	} else {
    		int last = 0, sum = 0;
    		for (register int i = 1; i <= m; i++) {
    			k[i] = read(), v[i] = read();
    			if (k[i] == 1) {
    				last = i;
    				sum = 0;
    			} else {
    				sum += v[i];
    			}
    		}
    		int C, K, V;
    		for (register int i = 1; i <= q; i++) {
    			C = read(), K = read(), V = read();
    			if (C < last) {///在左无影响
    				k[C] = K, v[C] = V;
    				printf ("%d
    ", sum);
    			} else if (C == last && K == 1) {//不变
    				printf ("%d
    ", sum);
    			} else if (C > last && K == 0) {//在右加答案
    				sum += (V - v[C]);
    				k[C] = 0, v[C] = V;
    				printf ("%d
    ", sum);
    			} else if (C == last && K == 0) {//换切点
    				k[C] = 0, v[C] = V;
    				sum += V;
    				for (register int j = last - 1; j >= 1; j--) {
    					if (k[j] == 1) {
    						last = j;
    						break;
    					} else {
    						sum += v[j];
    					}
    				}
    				printf ("%d
    ", sum);
    			} else if (C > last && K == 1) {//
    				sum = 0;
    				k[C] = 1, v[C] = V;
    				for (register int j = m; j >= 1; j--) {
    					if (k[j] == 1) {
    						last = j;
    						break;
    					} else {
    						sum += v[j];
    					}
    				}
    				printf ("%d
    ", sum);
    			}
    		}
    	}
    

    学到了吗? 如果学会了请把学废了打在评论区里23333

  • 相关阅读:
    js 原生ajax实现
    layer 查看图片
    c# 操作XML
    C# 扩展方法
    c# 依赖注入
    visual studio 快捷键
    HIS系统结算后,没有更新单据状态为“已结算”
    网络流四·最小路径覆盖 HihoCoder
    飞行员配对(二分图最大匹配) 51Nod
    开心的小Q 51Nod
  • 原文地址:https://www.cnblogs.com/hzoi-liujiahui/p/13853656.html
Copyright © 2011-2022 走看看