zoukankan      html  css  js  c++  java
  • UVA 699 The Falling Leaves

    https://vjudge.net/problem/UVA-699

    题目

    水得不行,就不说了……

    题解

    水题,只是注意数组不能开太大……直接就TLE了(缩小10倍用了0.9秒,服了……)

    AC代码(其实没有看的必要)

    #include<bits/stdc++.h>
    using namespace std;
    
    #define MAXN 1000007
    
    int ground[MAXN];//MAXN太大导致TLE(上界估计得太松)
    
    int lmax, rmax;
    
    inline void getint(int &ans) {
    	ans = 0;
    	bool sign = false;
    	char ch = getchar();
    	while(!isdigit(ch) && (ch!='-')) ch = getchar();
    	if(ch=='-') ch = getchar(), sign = true;
    	while(isdigit(ch)) {
    		ans = ans*10+ch-'0';
    		ch = getchar();
    	}
    	if(sign) ans = -ans;
    }
    
    inline void build(int pos) {
    	int v;
    	getint(v);
    	if(!~v) return;
    	if(pos<lmax) lmax=pos;
    	if(pos>rmax) rmax=pos;
    	ground[pos]+=v;
    	build(pos-1); build(pos+1);
    }
    
    int h=0;
    char st[1007];
    inline void putint(int k) {
    	int sti=0;
    	bool sign = false;
    	if(k<0) sign = true, k=-k;
    	do {
    		st[sti++]=k%10;
    		k/=10;
    	} while(k>0);
    	if(h+sign+sti>80) putchar('
    '), h=0;
    	else if(h>0) putchar(' ');
    	h+=sign+sti;
    	if(sign) putchar('-');
    	while(0<sti--) {
    		putchar(st[sti]+'0');
    	}
    }
    
    int main() {
    	int kase = 0;
    	while(1) {
    		if(kase) putchar('
    ');
    		kase++;
    		lmax = rmax = MAXN/2; h=0;
    		memset(ground, 0, sizeof ground);
    		build(MAXN/2);
    		if(ground[MAXN/2]==0) break;
    		
    		printf("Case %d:
    ", kase);
    		for(int i=lmax; i<=rmax; i++) {
    			putint(ground[i]);
    		}
    		putchar('
    ');
    	}
    	return 0;
    }
    

      

  • 相关阅读:
    多线程2
    多线程1
    Mybatis动态代理开发
    Mybatis的mapper.xml文件也是要加文件头的
    ssm框架只使用mybatis配置sqlmapconfig.xml
    ssm整合之web.xml配置
    SpringMVC三大组件的配置
    spring开启注解配置
    如何开发 Sublime Text 2 的插件
    ASP.NET MVC 5改进了基于过滤器的身份验证
  • 原文地址:https://www.cnblogs.com/sahdsg/p/10394420.html
Copyright © 2011-2022 走看看