第二杯半价

有floor(n/2)杯享受半价,ceil(n/2)杯原价。

#include <bits/stdc++.h>
using namespace std;
#define echo(x) cout<<#x" = "<<(x)<<endl
#define cpp_fast_io cin.tie(0); cout.tie(0); ios::sync_with_stdio(0);
#define endl "\n"
#define SI __inline__ __attribute((always_inline))

int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n, x;
		cin>>n>>x;
		int b=(n>>1)*(x+1>>1) + (n+1>>1)*x;
		cout<<b<<endl;
	}
}

反方向的钟

分钟原样输出即可,问题是小时。将24小时制的取值范围0~23的h模12,得到取值范围0~11的数字,如果把0~11的范围称为一圈,则第1圈对应am,第2圈对应pm。然后如果是0则改为12。

#include <bits/stdc++.h>
using namespace std;
#define echo(x) cout<<#x" = "<<(x)<<endl
#define cpp_fast_io cin.tie(0); cout.tie(0); ios::sync_with_stdio(0);
#define endl "\n"
#define SI __inline__ __attribute((always_inline))

int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int A, B;
		cin>>A>>B;
		int a=A%12;
		bool pm = A>=12;
		if(a==0) a=12;
		cout<<a<<" "<<B<<" "<<"ap"[pm]<<"m"<<endl;
	}
}

素数三元组

a+b=c

a<b<c

a,b,c 都是素数。

注意到2是唯一的偶数素数,也是最小的素数。

可知c>2。从而c是奇数。从而a与b中有1个奇数和1个偶数。从而a=2。

因此直接筛出素数然后找孪生素数(相差2的素数对)即可。

#include <bits/stdc++.h>
using namespace std;
#define echo(x) cout<<#x" = "<<(x)<<endl
#define cpp_fast_io cin.tie(0); cout.tie(0); ios::sync_with_stdio(0);
#define endl "\n"
#define SI __inline__ __attribute((always_inline))

const int N=1e6;
const int I=78498;
int prime[I];
bool not_prime[N+1];
int s;
void ass()
{
	not_prime[0]=not_prime[1]=true;
	for(int i=2;i<=N;i++)
	{
		if(not not_prime[i]) prime[s++]=i;
		for(int j=0;j<s and prime[j]*i<=N;j++)
		{
			not_prime[i*prime[j]]=true;
			if(i%prime[j]==0) break;
		}
	}
}

SI bool is_prime(int x){ return not not_prime[x]; }

int A[N+1];
void bss()
{
	A[0]=0;
	for(int n=0;n<=N;n++)
	{
		A[n+1]=A[n];
		if(is_prime(n-1) and is_prime(n+1)) A[n+1]++;
	}
}

int main()
{
	cpp_fast_io
	ass();
//	echo(prime[I-1]);
	bss();
	int t;
	cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		cout<<A[n]<<endl;
	}
}

今日是?

强烈谴责这道题。根据题目最下方的备注的提示,去牛客找除夕那天的比赛(虽然除夕和今天我都没人陪,但是除夕那场我没打)。找到类似的题目今晚是?。然后查看题解(很幸运这题恰好有一篇题解,如果没有就只能翻别人的AC代码)。类比该题的思路,猜测本题就是“天外有天”去掉“人”,即“二外有二”,还猜对了

#include <bits/stdc++.h>
using namespace std;

int main()
{
	puts("二外有二");
}

时间银河

考虑1到x年之间有多少天,设为f(x)天。答案就是f(b)-f(a-1)。

注意到连续的400年中一定有恰好97个闰年,从而有恰好146097天。因此设x=400k+r,则400k的贡献是k*146097天;r<400,所以r的贡献可以暴力打表计算。

#include <bits/stdc++.h>
using namespace std;
#define cpp_fast_io cin.tie(0), cout.tie(0), ios::sync_with_stdio(0);
#define endl "\n"
#define echo(E) cout<<#E" = "<<(E)<<endl
#define int int64_t
const int b[400]={ // b[i] = y  <==>  1年~i年中有y天 
0,365,730,1095,1461,1826,2191,2556,2922,3287,3652,4017,4383,4748,5113,5478,5844,
6209,6574,6939,7305,7670,8035,8400,8766,9131,9496,9861,10227,10592,10957,11322,
11688,12053,12418,12783,13149,13514,13879,14244,14610,14975,15340,15705,16071,
16436,16801,17166,17532,17897,18262,18627,18993,19358,19723,20088,20454,20819,
21184,21549,21915,22280,22645,23010,23376,23741,24106,24471,24837,25202,25567,
25932,26298,26663,27028,27393,27759,28124,28489,28854,29220,29585,29950,30315,
30681,31046,31411,31776,32142,32507,32872,33237,33603,33968,34333,34698,35064,
35429,35794,36159,36524,36889,37254,37619,37985,38350,38715,39080,39446,39811,
40176,40541,40907,41272,41637,42002,42368,42733,43098,43463,43829,44194,44559,
44924,45290,45655,46020,46385,46751,47116,47481,47846,48212,48577,48942,49307,
49673,50038,50403,50768,51134,51499,51864,52229,52595,52960,53325,53690,54056,
54421,54786,55151,55517,55882,56247,56612,56978,57343,57708,58073,58439,58804,
59169,59534,59900,60265,60630,60995,61361,61726,62091,62456,62822,63187,63552,
63917,64283,64648,65013,65378,65744,66109,66474,66839,67205,67570,67935,68300,
68666,69031,69396,69761,70127,70492,70857,71222,71588,71953,72318,72683,73048,
73413,73778,74143,74509,74874,75239,75604,75970,76335,76700,77065,77431,77796,
78161,78526,78892,79257,79622,79987,80353,80718,81083,81448,81814,82179,82544,
82909,83275,83640,84005,84370,84736,85101,85466,85831,86197,86562,86927,87292,
87658,88023,88388,88753,89119,89484,89849,90214,90580,90945,91310,91675,92041,
92406,92771,93136,93502,93867,94232,94597,94963,95328,95693,96058,96424,96789,
97154,97519,97885,98250,98615,98980,99346,99711,100076,100441,100807,101172,
101537,101902,102268,102633,102998,103363,103729,104094,104459,104824,105190,
105555,105920,106285,106651,107016,107381,107746,108112,108477,108842,109207,
109572,109937,110302,110667,111033,111398,111763,112128,112494,112859,113224,
113589,113955,114320,114685,115050,115416,115781,116146,116511,116877,117242,
117607,117972,118338,118703,119068,119433,119799,120164,120529,120894,121260,
121625,121990,122355,122721,123086,123451,123816,124182,124547,124912,125277,
125643,126008,126373,126738,127104,127469,127834,128199,128565,128930,129295,
129660,130026,130391,130756,131121,131487,131852,132217,132582,132948,133313,
133678,134043,134409,134774,135139,135504,135870,136235,136600,136965,137331,
137696,138061,138426,138792,139157,139522,139887,140253,140618,140983,141348,
141714,142079,142444,142809,143175,143540,143905,144270,144636,145001,145366,
145731
};

int f(int x)
{
	int k=x/400;
	int r=x%400;
	return k*(146097) + b[r];
}


int32_t main()
{
//	cpp_fast_io
	int t;
	cin>>t;
	while(t--)
	{
		int a, b;
		cin>>a>>b;
		cout<<f(b)-f(a-1)<<endl;
	}
}

白毛飞飞

所有的i,ai<=i,则为yes。

#include <bits/stdc++.h>
using namespace std;

[[noreturn]] void NO(){
	puts("NO");
	exit(0);
}
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		int x;
		cin>>x;
		if(x>i) NO();
	}
	puts("YES");
}