zoukankan      html  css  js  c++  java
  • Cardiogram

    题目链接

    CF435C

    题意

    A cardiogram is a polyline with the following corners:

    ((0;0), (a_1;a_1), (a_1+a_2;a_1-a_2),...,(sum_{i=1}^n{a_i};sum_{i=1}^n{(-1)^{i+1}a_i}))

    That is, a cardiogram is fully defined by a sequence of positive integers (a_1, a_2, ..., a_n).

    Your task is to paint a cardiogram by given sequence (a_i).

    Input
    The first line contains integer n (2 ≤ n ≤ 1000). The next line contains the sequence of integers a 1, a 2, ..., a n (1 ≤ a i ≤ 1000). It is guaranteed that the sum of all a i doesn't exceed 1000.

    Output
    Print (max |y_i - y_j|) lines (where y k is the y coordinate of the k-th point of the polyline), in each line print characters. Each character must equal either « / » (slash), « » (backslash), « » (space). The printed image must be the image of the given polyline. Please study the test samples for better understanding of how to print a cardiogram.

    Note that in this problem the checker checks your answer taking spaces into consideration. Do not print any extra characters. Remember that the wrong answer to the first pretest doesn't give you a penalty.

    思路

    • 我的思路是从上到下一行行处理,然后一行里面按两点之间分块,一块块处理。
    • 如果这一块靠左的点的y坐标大于等于现在这一行,而右边这个点的y坐标小于等于现在这一行,那么这一块中有一个要输出符号'',其他输出空格。同理可以推出其他输出'/'的情况,其他情况都是输出空格。
    • 通过给的式子,可以知道,每两个点之间的连线的斜率一定是 1 或者 -1,因此可以推出哪一个地方输出'','/', 其他地方都输出空格。
    • 题目有说一共有(max |y_i - y_j|) lines,但是!!!我错在没有考虑到(0;0)!!!!卡了一个钟,我才发现啊啊啊,日常忘记初始化,边界情况,日常不会写博弈和难题。

    代码

    #include<bits/stdc++.h>
    using namespace std;
    const int MAXN=1005;
    int n;
    typedef pair<int,int> pa;
    pa a[MAXN];
    int main(){
    //	freopen("out.txt","w",stdout);
    	scanf("%d",&n);
    	int sumx=0,sumy=0;
    	int mxy=0,mny=0;
    	int t;
    	a[0]=make_pair(0,0);
    	for(int i=1;i<=n;i++)
    	{
    		scanf("%d",&t);
    		sumx+=t;
    		if(i&1)
    			sumy+=t;
    		else sumy-=t;
    		a[i]=make_pair(sumx,sumy); 
    		mxy=mxy<sumy?sumy:mxy;
    		mny=mny>sumy?sumy:mny;
    	}
    	for(int i=mxy;i>=mny;i--){
    		for(int j=0;j<n;j++){			
    			if(a[j].second<=i&&a[j+1].second>=i){
    				int difY = a[j+1].second-a[j].second;
    				int difX = a[j+1].first-a[j].first;	
    				for(int z=1;z<=difX;z++){
    					if(z==(i-a[j].second))
    						printf("/");
    					else printf(" ");
    				}
    			}
    			else if(a[j].second>=i&&a[j+1].second<=i){ 
    				int difY = a[j].second-a[j+1].second;
    				int difX = a[j+1].first-a[j].first;
    				for(int z=0;z<difX;z++){
    					if(z==(a[j].second-i))
    						printf("\");
    					else printf(" ");
    				}
    			} 
    			else{
    				for(int z=a[j].first;z<a[j+1].first;z++) printf(" ");
    			} 
    		}
    		printf("
    ");
    	}
    	return 0;
    }
    
  • 相关阅读:
    SQL注入攻击三部曲之进阶篇
    SQL注入攻击三部曲之入门篇
    父页面(JSP页面)传参数到子页面(JSP页面)
    Flex弹出窗口请求Action函数
    dojo表格分页插件报错
    堆栈溢出问题 调试到位置(test dword ptr [eax],eax ; probe page.)局部数组变量定义所分配的最大空间为1M
    改装的表格
    FusionCharts饼图中label值太长怎么解决
    dojo中的dojox/grid/EnhancedGrid表格报错
    dojo表格分页之各个参数代表的意义(一)
  • 原文地址:https://www.cnblogs.com/xuwanwei/p/12831459.html
Copyright © 2011-2022 走看看