C - Pen Counts

/*
发现比赛的时候很多人水过= =
各种打表 。。。
我的解法:
	枚举最短的边
	假设三角形的边长为x<=y<=z
	则有如下关系:
		x+y+z=n
		x+y>z>=max(x,y)
	将z用n-x-y替换,就可以得出对于每个确定x,的y的范围;
	max(x-1,n/2-x)<=y<(n-x)/2
	剩下就仅需要判断一下特殊情况
*/
//#pragma comment(linker, "/STACK:167772160")
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <ctime>
#include <cmath>
#include <cassert>
//#include <fstream>
#include <stack>
#include <cctype>
#define MP make_pair
#define PB push_back
#define SZ(x) (int)x.size()
#define INF 1<<29
#define pii pair<int,int>
#define pll pair<LL,LL>
#define vi vector<int>
#define L(x) x<<1
#define R(x) x<<1|1
#if(_WIN32||__WIN32__)
    #define LL __int64
    #define ll I64
#else
    #define LL long long
#endif
//#define Local

using namespace std;

int calc(int n)
{
	int sum=0;
	for(int i=1;i<=(n)/3;i++)
	{
		sum+=((n-i)/2-max((n)/2-i,i-1))*2;
		if(n-i*2<i+i)
			sum--;
		if((n-i)/2*2==n-i)
			sum--;
		if(n-i*2==i)
			sum++;
	}
	return sum;
}

int main()
{
	int n,Case,T;
	scanf("%d",&T);
	while(T--)
	{
		scanf("%d %d",&Case,&n);
		printf("%d %d\n",Case,calc(n));
	}
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值