Exemplo n.º 1
0
int main() {
    read();
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            s[i][j] = a[i][j] + s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1];
        }
    }
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            if (a[i][j] == 0) {
                w[i][j] = h[i][j] = 0;
                continue;
            }
            w[i][j] = 1 + w[i][j - 1];
            h[i][j] = 1 + h[i - 1][j];
        }
    }
    int best = -1;
    for (int i = 2; i < n; ++i) {
        for (int j = 2; j < m; ++j) {
            int width = w[i][j], height = h[i][j];
            if (width == 0 || width == j) 
                continue;
            if (height == 0 || height == i) 
                continue;
            int area = width * height;
            if (getSum(i, j, width, height) == area && 
                getSum(i + 1, j + 1, width + 2, height + 2) == area) {
                    best = max(best, width * height);
                }
        }
    }
    printf("%d", best);
}
Exemplo n.º 2
0
void advance(int k)			//递归
{
	if(k<0) return;//k为-1时,确定已无解了,保存-1退出递归

	v[k]=1;
	if(getSum()==Y)
	{
		output();
		v[k]=0;
	}
	if(getSum()<Y)			//深度优先
	{
		if(k<9)
			advance(k+1);
	}
	else					//回溯
	{
		v[k]=0;
		for(;k>=0;k--)
			if(v[k]==1)
			{
				v[k]=0;
				advance(k+1);
			}
		if(k<0) advance(k);//k为-1时,确定已无解了,保存-1退出递归
	}
}
int main()
{
    printf("%lld\n", getSum("siis", "12", 30000, 500000, "300"));
    printf("%lld\n", getSum("ssi", "150", "150", 100));

    return 0;
}
Exemplo n.º 4
0
 inline int getSum(int x, int y, int w, int h) { 
   // Get the sum of pixel values in the window (ONLY FOR SINGLE-CHANNEL IMAGE!)
   // Note this function do NOT check, for speed, whether or not the data[] is ready.
   //   Use appropiately, otherwise it will crash.
   int x0 = x-1, y0 = y-1, x1 = x+w-1, y1 = y+h-1;
   return ( getSum(x1,y1) - getSum(x1,y0) - getSum(x0,y1) + getSum(x0,y0) ); 
 }
Exemplo n.º 5
0
void Economics::calculateEconomics()
{
  //year 0:  First cost
  //year 1:  payment
  //year 15: equipment/maintenance --
  m_gasCostSavings = m_refBuilding->gasCost() - m_selBuilding->gasCost();
  m_gasUseSavings = m_refBuilding->gasUse() - m_selBuilding->gasUse();
  m_elecCostSavings = m_refBuilding->elecCost() - m_selBuilding->elecCost();
  m_elecUseSavings = m_refBuilding->elecUse() - m_selBuilding->elecUse();
  m_districtHeatCostSavings = m_refBuilding->districtHeatCost() - m_selBuilding->districtHeatCost();
  m_districtHeatUseSavings = m_refBuilding->districtHeatUse() - m_selBuilding->districtHeatUse();
  m_districtCoolCostSavings = m_refBuilding->districtCoolCost() - m_selBuilding->districtCoolCost();
  m_districtCoolUseSavings = m_refBuilding->districtCoolUse() - m_selBuilding->districtCoolUse();
  m_totalEnergyCostSavings = m_gasCostSavings + m_elecCostSavings + m_districtHeatCostSavings + m_districtCoolCostSavings;
  m_totalEnergyUseSavings = m_gasUseSavings + m_elecUseSavings + m_districtHeatUseSavings + m_districtCoolUseSavings;
  calculateCashFlowSavings( m_refBuilding->cashFlows(), m_selBuilding->cashFlows() );
  m_capitalCostSavings = - m_cashFlowSavings.at(0);  //negate for cash flow into building
  m_energyCostSavings = - m_totalEnergyCostSavings; //negate for cash flow into of building
  m_capitalAnalysisEnergyCostSavings = m_capitalCostSavings + ( m_analysisPeriod * m_energyCostSavings );
  m_NPV = getSum( m_discountedCashFlowSavings );
  if(!getIRR( m_cashFlowSavings, m_IRR )){
    m_IRR = 0;
  }
  m_SPB = payBack( m_cashFlowSavings );
  m_DPB = payBack( m_discountedCashFlowSavings );

  m_FV = getFV( m_discountRate, m_analysisPeriod, m_cashFlowSavings.at(0) );

  //add inflations to cash flows
  calculateCashFlowSavings( m_refBuilding->cashFlows_Inflation(), m_selBuilding->cashFlows_Inflation() );
  m_TLCC_Savings = getSum( m_discountedCashFlowSavings );
  m_LCOE_Cost = levelizedCostOfEnergy( m_TLCC_Savings, ltCost );
  m_LCOE_Energy = levelizedCostOfEnergy( m_TLCC_Savings, ltEnergy );
  m_DPB_TLCC = payBack( m_discountedCashFlowSavings );
}
Exemplo n.º 6
0
double Economics::getTLCC( BuildingType buildingType )
{
  double result = 0.0;
  switch ( buildingType )
  {
    case btReference:
    {
      if ( m_refBuilding->cashFlows_Inflation().size() > 0 ) 
        result = - getSum( m_refBuilding->cashFlows_Inflation() );
      else
        result = 0;
    }
    break; //begin

    case btSelected:
    {
      if ( m_selBuilding->cashFlows_Inflation().size() > 0 ) 
        result = - getSum( m_selBuilding->cashFlows_Inflation() );
      else
        result = 0;
    }
    break; //begin
  } //case
  return result;
}
Exemplo n.º 7
0
int getSum(int num){
    if(num == 1 || num == 2){
        return 1;
    }else{
        return getSum(num - 1) + getSum(num - 2);
    }
}
 int sumRange(int i, int j) {
     
     int sum1 = getSum(j);
     int sum2 = getSum(i-1);
     
     return sum1-sum2;
 }
 NumMatrix(vector<vector<int>> &matrix):Matrix(matrix) {
     int m = matrix.size();
     for(int i=0;i<m;++i){
         for(int j=0;j<matrix[0].size();++j){
             Matrix[i][j] += getSum(i-1,j)+getSum(i,j-1)-getSum(i-1,j-1);
         }
     }
 }
Exemplo n.º 10
0
void treeCalcSum(node **root) {
  unsigned long long new_sum;
  new_sum = 0;
  if (*root == 0) return;

  new_sum += getSum((*root)->child[LEFT]);
  new_sum += getSum((*root)->child[RIGHT]);
  (*root)->sum = new_sum + (*root)->value;
}
 int getSum(TreeNode *root, unordered_map<int, int> &map, int &maxCount) {
     if (!root) {
         return 0;
     }
     int sum = root->val + getSum(root->left, map, maxCount) + getSum(root->right, map, maxCount);
     map[sum]++;
     maxCount = max(map[sum], maxCount);
     return sum;
 }
Exemplo n.º 12
0
 int getSum(TreeNode* root, bool is_left) {
     int sum = 0;
     if (root != NULL) {
         sum += getSum(root->left, true);
         sum += getSum(root->right, false);
         if (root->left == NULL && root->right == NULL && is_left) {
             sum += root->val;
         }
     }
     return sum;
 }
Exemplo n.º 13
0
int getSum(Tree* t) {
    if(!t) {
        return 0;
    }
    if(t->key == '*') {
        return getSum(t->left) + getSum(t->right);
    }
    else {
        return t->weight * t->level + getSum(t->left) + getSum(t->right);
    }
}
Exemplo n.º 14
0
	inline int getSum(int ll, int lr, int ql, int qr, int root)
	{
		if (ql <= ll && qr >= lr) return sum_tree[root];

		if (lr < ql || ll > qr) return 0;

		int lm = (ll + lr) / 2;
		return getSum(ll, lm, ql, qr, 2 * root + 1) +
			getSum(lm + 1, lr, ql, qr, 2 * root + 2);

	}
Exemplo n.º 15
0
Arquivo: s1246.cpp Projeto: were/progs
int main(int argc, const char * argv[]) {
	scanf("%d%d%d%d%d%d", &M, &N, &b, &a, &d, &c);
	for (int i = 1; i <= N; ++i) {
		for (int j = 1; j <= M; ++j) {
			scanf("%d", s[i] + j);
			s[i][j] += s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1];
		}
	}
	for (int i = 1, k = b - d - 1; i + c - 1<= N; ++i) {
		int l = 1, r = 0;
		for (int j = 1; j + d - 1 <= M; ++j) {
			tmp[j] = getSum(i, j, i + c - 1, j + d - 1);
			while (l <= r && q[l] < j - k + 1) {
				++l;
			}
			while (l <= r && tmp[q[r]] >= tmp[j]) {
				--r;
			}
			q[++r] = j;
			if (j >= k) {
				idx[i][j - k + 1] = q[l];
			}
		}
	}
	for (int j = 1, k = a - c - 1; j + (c - 1) + (k - 1) <= M; ++j) {
		int l = 1, r = 0;
		for (int i = 1; i < N; ++i) {
			tmp[i] = getSum(i, idx[i][j], i + c - 1, idx[i][j] + d - 1);
			while (l <= r && q[l] < i - k + 1) {
				++l;
			}
			while (l <= r && tmp[q[r]] >= tmp[i]) {
				--r;
			}
			q[++r] = i;
			if (i >= k) {
				if (i - k >= 1 && j - 1 >= 1 && i - k + a - 1 <= N && j - 1 + b - 1 <= M) {
					int tmpAns = getSum(i - k, j - 1, i - k + a - 1, j - 1 + b - 1);
					tmpAns -= tmp[q[l]];
					if (tmpAns > ans) {
						ans = tmpAns;
						x1 = i - k;
						y1 = j - 1;
						x2 = q[l];
						y2 = idx[q[l]][j];
					}
				}
			}
		}
	}
	printf("%d %d\n%d %d\n", y1, x1, y2, x2);
    return 0;
}
Exemplo n.º 16
0
 void getSum(int x, int y, int w, int h, int val[3]) { 
   // Get the sum of pixel values in the window (ONLY FOR THREE-CHANNEL IMAGE!)
   // Note this function do NOT check, for speed, whether or not the data[] is ready.
   //   Use appropiately with valid window range (x,y>0), otherwise it will crash.
   int x0 = x-1, y0 = y-1, x1 = x+w-1, y1 = y+h-1;
   x0 -= 1;  y0 -= 1;
   getSum( x0, y0, v00 );   getSum( x1, y0, v10 );
   getSum( x0, y1, v01 );   getSum( x1, y1, v11 );
   val[0] = v11[0] - v10[0] - v01[0] + v00[0];
   val[1] = v11[1] - v10[1] - v01[1] + v00[1];
   val[2] = v11[2] - v10[2] - v01[2] + v00[2];
 }
Exemplo n.º 17
0
/**
 * Definition for binary tree
 * struct TreeNode {
 *     int val;
 *     struct TreeNode *left;
 *     struct TreeNode *right;
  * };
 */
void getSum(struct TreeNode* root, int cur, int* res) {
    if (root == NULL)
        return;
        
    cur = cur * 10 + root->val;
    if (root ->left == NULL && root->right == NULL) {
        res[0] += cur;
        return;
    }
    
    getSum(root->left, cur, res);
    getSum(root->right, cur, res);
}
Exemplo n.º 18
0
int getSum(int f, int t, int x){
	if(f != t)
		push(x);
	if(f == t){
		return f;
	}else{
		if(getAns(ls).sum < X){
			X -= getAns(ls).sum;
			return getSum(mid + 1, t, rs);
		}else
			return getSum(f, mid, ls);
	}
}
Exemplo n.º 19
0
long long int iTree::getSum(const int &start, const int &end, const int iStart, const int iEnd, const int pos)
{
    if(start == iStart && end == iEnd)
        return data[pos];

    //printf("looking for %d %d %d %d %d %d\n", start, end, iStart, iEnd, pos, data[pos]);
    const int iMid = (iStart + iEnd) / 2;
    if(end <= iMid)
        return getSum(start, end, iStart, iMid, pos * 2) % MOD;

    if(start > iMid)
        return getSum(start, end, iMid + 1, iEnd, pos * 2 + 1) % MOD;

    return (getSum(start, iMid, iStart, iMid, pos * 2) + getSum(iMid + 1, end, iMid + 1, iEnd, pos * 2 + 1)) % MOD;
}
Exemplo n.º 20
0
    NumMatrix(vector<vector<int>> &matrix) {

        int row, col;
        row = matrix.size();
        if(row != 0) col = matrix[0].size();
        else col = 0;

        cout << "width :" << col << " height : " << row << endl;

        if (row == 0 || col == 0)
            return;

        selfmatrix = vector<vector<int>>(row+1, vector<int>(col+1, 0));
        summatrix = vector<vector<int>>(row+1, vector<int>(col+1, 0));

        for(int i=0; i<row; i++) {
            for(int j=0; j<col; j++) {
                selfmatrix[i][j] = matrix[i][j];
                summatrix[i][j] = getSum(i,j,matrix);
            }
        }

        cout << "HELLO";

    }
Exemplo n.º 21
0
 bool normalize(T npdf[]=NULL) {
   T sum = getSum();
   if (sum == 0) return false; 
   if (npdf) for (int i=0; i<size; i++) npdf[i] = data[i] / sum;
   else      for (int i=0; i<size; i++) data[i] /= sum;
   return true;
 }
Exemplo n.º 22
0
int main() {
	int test_case;
	scanf("%d", &test_case);
	while (test_case--) {
		scanf("%d%d", &moive_number, &watch_number);
		init();
		int top = moive_number;
		for (int i = 1; i <= watch_number; i++) {
			int watch_moive;
			scanf("%d", &watch_moive);
			int cnt_location = location[watch_moive];
			int ans = getSum(cnt_location);
			if (i == 1) {
				printf("%d", moive_number - ans);
			}
			else {
				printf(" %d", moive_number - ans);
			}
			update(cnt_location, -1);
			top++;
			location[watch_moive] = top;
		}
		printf("\n");
	}
	return 0;
}
int handleData(coap_rw_buffer_t* scratch,
               const coap_packet_t* inpkt,
               coap_packet_t* outpkt,
               uint8_t id_hi, uint8_t id_lo)
{
    int temperature = getTemperature(scratch, inpkt, outpkt, id_hi, id_lo);

    printf("Received temperature %d\n", temperature);

    addValue(temperature);

    int average_temp = getSum() / getCount();

    printf("Average temperature %d\n", average_temp);

    if (average_temp < YELLOW_TEMP * 100) {
        setLed(LEDGREEN_PIN);
    } else {
        if (average_temp < RED_TEMP * 100) {
            setLed(LEDYELLOW_PIN);
        } else {
            setLed(LEDRED_PIN);
        }
    }

    return 0;
}
Exemplo n.º 24
0
/*Finds the rectangular left uppper point of which is specified having the max sum inside*/
double maxSumConstPoint(double table[][COL_COUNT], int nRow, int leftUpY, int leftUpX, int* rightDownY, int* rightDownX){
	int rDX;	/*x coordinate of the right down corner of the rec*/
	int rDY;	/*y coordinate of the right down corner of the rec*/
	double temp;
	/*initialize the rectangular with the one including only one point*/
	double sum=table[leftUpX][leftUpY];
	*rightDownY=leftUpY;
	*rightDownX=leftUpX;

	/*Try all feasible rectangulars by changing the right down corner*/
	for(rDY=leftUpY; rDY<nRow; ++rDY){
		for(rDX=leftUpX; rDX<COL_COUNT; ++rDX){
			temp=getSum(table, leftUpY, leftUpX, rDY, rDX);

			if(temp>sum){
				/*a better rectangular is found, perform an update */
				sum=temp;
				*rightDownY=rDY;
				*rightDownX=rDX;
			}
		}
	}

	return sum;
}
Exemplo n.º 25
0
void Get(){
	scanf("%d", &X);
	if(X > getAns(1).sum)
		puts("Reject Get");
	else
		printf("Get at %d\n", getSum(1, N, 1));
}
Exemplo n.º 26
0
int getAverage(int n,int m)//获得序列的平均值
{
	int t=n/m;//多少个分组
	int i=0;
	for(i=0;i<t;++i)
	{
		//Sij=Sj-Si
		average[i]=(getSum((i+1)*m)-getSum(i*m))/m;
	}
	if(n%m !=0)//有多出来的部分
	{
		average[i]=(getSum(n)-getSum(i*m))/(n-i*m);
		++i;
	}
	return i;//返回有多少个组
}
Exemplo n.º 27
0
void SnpBuffer::drawSnpSums(QImage *image, int top, int bottom, int posStart, int posEnd, int bins) const
{
	if ( ready() )
	{
		drawSnps(image, getSum(), top, bottom, posStart, posEnd, bins, getBins());
	}
}
Exemplo n.º 28
0
int main(int argc, const char * argv[]) {
    int num;
    int getSum(int);
    scanf("%d", &num);
    printf("%d", getSum(num));
    return 0;
}
Exemplo n.º 29
0
// Driver program to test above functions
int main()
{
    long long int n,Q;
    freopen("input.txt","r",stdin);
    //printf("%llu\n",pow(2,20));
    scanf("%lld%lld",&n,&Q);
    //prlong long intf("%d %d\n",n,Q);
    long long int arr[1000007];
    for(int i=0;i<n;i++) scanf("%lld",&arr[i]);
    // Build segment tree from given array
    long long int *st = constructST(arr, n);
    for(long long int i=0;i<Q;i++)
    {
        char a;
        long long int b,c;
        a = getchar();
        while(a=='\n' || a==' ')
        a = getchar();
        scanf("%lld%lld",&b,&c);
        //prlong long intf("%c %d %d\n",a,b,c);
        if(a=='S')
        printf("%llu\n", getSum(st, n, b, c));

    // Update: set arr[1] = 10 and update corresponding segment
    // tree nodes
    else if(a=='G')
        updateValue(arr, st, n, b, c);

    // Find sum after the value is updated
    else
        updateValue(arr, st, n, b, -c);
    }
    return 0;
}
Exemplo n.º 30
0
int main(int argc, char *argv[])
{
	// We assume that the element number is the power of 2 for simplification.
	const int elemNum = 1 << 22;
	int arraySize = elemNum * sizeof(int);
	// host memory
	int *h_idata;

	h_idata = malloc(arraySize);
	
	FILE *fp;
	if((fp = fopen(argv[1], "rb")) == NULL)
	{
		printf("Can not open input file!\n");
		exit(0);
	}
	int i;
	for (i = 0; i < elemNum; ++i)
	{
		fscanf(fp, "%d", &h_idata[i]);
	}
	fclose(fp);

	struct timespec start, end;
	double totalTime;
	clock_gettime(CLOCK_REALTIME,&start);
	int sum = getSum(h_idata, elemNum);
	clock_gettime(CLOCK_REALTIME,&end);
	totalTime = (double)(end.tv_sec-start.tv_sec)*1000+(double)(end.tv_nsec-start.tv_nsec)/(double)1000000L;

	float bandwidth = elemNum * sizeof(int) / (totalTime / 1000) / 1024 / 1024 / 1024;
	printf("%d %fms %fGB/s\n", sum, totalTime, bandwidth);
	return 0;
}