A Cat
-
题意
-
思路
一看数据范围肯定是从二进制考虑呀
0 0 0
1 0 0
0 1 0
1 1 0
0 0 1
1 0 1
0 1 1
1 1 1…
从低位到高位
所以考虑最高位,又因为异或的性质——相同为
0
0
0 ,不同为
1
1
1。
暂且到此为止吧,这太难了。
- 正确思路
题意: 给出一个区间[ l , r ] [l,r][l,r]区间内的数字是l , l + 1 , l + 2 , . . . , r l,l+1,l+2,…,rl,l+1,l+2,…,r,让你找到一个最大的区间使得区间异或和小于s ss.
我们打表找几项就会发现区间异或和的性质如果是偶数开始那么往后四位后异或和为 0 00, 比如 2 , 3 , 4 , 5 2,3,4,52,3,4,5 异或和为0 00, 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 2,3,4,5,6,7,8,92,3,4,5,6,7,8,9异或和也为 0 00,这样我们就先从区间的第一个偶数开始选择然后找到不大于区间的 k kk个四位数,然后枚举剩下区间的异或和就行了。
- 代码
ll check(ll l,ll r)
{
ll sum=0;
if(r-l+1<=1000)
{
for(ll i=l; i<=r; i++)
sum^=i;
return sum;
}
else
{
while(l%4!=0)
sum^=l,l++;
while(r%4!=3)
sum^=r,r--;
return sum;
}
}
int main()
{
ll t;
cin>>t;
while(t--)
{
ll l,r,s;
cin>>l>>r>>s;
ll fuck=0;
ll ma=-1;
for(int i=0; i<=3; i++)
{
for(int j=0; j<=3; j++)
{
ll L=l+i;
ll R=r-j;
if(R<L)
break;
if(check(L,R)<=s)
{
ma=max(R-L+1,ma);
}
}
}
printf("%lld\n",ma);
}
}
C
- 思路
就是偶数的
就是素数的个数,我服了,要输出 “Yes", w a wa wa 了”YES"。抱歉 C F CF CF 打多了 - 代码
#include <bits/stdc++.h>
using namespace std;
#define ll long long
bool isprime(int n)
{
if (n == 1||n == 2) {
return true;
}
for (int i = 2;i * i <= n;i ++) {
if (n % i == 0) {
return false;
}
}
return true;
}
int main()
{
int t;cin>>t;
while (t--) {
int L,R; cin>>L>>R;
if (R - L >= 200) {
cout<<"Yes"<<endl;
} else {
int cnt = 0;
for (int i = L ;i <= R;i ++) {
if (isprime(i)) {
cnt ++;
}
}
if (cnt * 3 < (R-L+1)) {
cout<<"Yes"<<endl;
} else {
cout<<"No"<<endl;
}
}
}
}
F题
-
题意
-
思路
打表的方法也是刚学的,对每个x,枚举a,b,二分找c 。 反正最好就是按一定格式打表出来,直接复制存到一个数组交上去就行了。 -
代码
#include <bits/stdc++.h>
#define debug(x) cout << #x << ": " << x << endl
using namespace std;
typedef long long ll;
const int MAXN=2e5+7;
const int INF=0x3f3f3f3f;
const int MOD=1e9+7;
int ans[][3]=
{
-5000,0,5000,
-5000,1,5000,
-4373,-486,4375,
-5,4,4,
11111,0,0,
11111,0,0,
-637,-205,644,
-169,44,168,
-5000,2,5000,
-216,-52,217,
-650,-353,683,
-695,-641,843,
-11,7,10,
11111,0,0,
11111,0,0,
-265,-262,332,
-4114,-588,4118,
-3331,2195,2977,
-1373,-1276,1671,
-95,47,91,
-2816,-741,2833,
-401,-287,445,
11111,0,0,
11111,0,0,
-10,8,8,
-2683,1839,2357,
-2107,237,2106,
-5000,3,5000,
-2268,-249,2269,
-233,-69,235,
11111,0,0,
11111,0,0,
11111,0,0,
11111,0,0,
-1555,-244,1557,
-1120,-509,1154,
-3223,2358,2731,
-444,-84,445,
-27,16,25,
11111,0,0,
11111,0,0,
11111,0,0,
11111,0,0,
-823,-307,837,
-7,-5,8,
-2369,1709,2025,
-758,-473,815,
-141,49,139,
-3950,-1247,3991,
11111,0,0,
11111,0,0,
-796,602,659,
11111,0,0,
-2370,1518,2141,
-3885,-648,3891,
-3329,1837,3131,
-672,505,559,
-998,361,982,
11111,0,0,
11111,0,0,
-1201,-163,1202,
-966,668,845,
-2744,-1561,2903,
-161,102,146,
-5000,4,5000,
-929,403,903,
1,1,4,
11111,0,0,
11111,0,0,
-403,134,398,
-2359,824,2325,
-533,401,443,
-432,-104,434,
-335,-146,344,
11111,0,0,
11111,0,0,
11111,0,0,
11111,0,0,
-2080,-829,2123,
-706,-196,711,
-1300,-706,1366,
-2368,-1719,2638,
-1317,847,1188,
-3707,1315,3651,
11111,0,0,
11111,0,0,
11111,0,0,
-4126,-1972,4271,
-1390,-1282,1686,
-2514,1953,2036,
-1803,365,1798,
-3389,-2912,3992,
-4052,861,4039,
-248,-98,253,
11111,0,0,
11111,0,0,
-22,14,20,
-3168,-991,3200,
-2101,-1638,2391,
-893,-622,984,
-1797,-903,1870,
-2327,319,2325,
-239,118,229,
11111,0,0,
11111,0,0,
-7,-4,8,
-2689,-1165,2760,
-1309,947,1117,
-1165,-948,1345,
-2948,853,2924,
11111,0,0,
-4793,-2312,4966,
11111,0,0,
11111,0,0,
11111,0,0,
-12,8,11,
-1906,-757,1945,
-896,-555,962,
-4328,383,4327,
-3677,-1673,3789,
-2804,1219,2725,
11111,0,0,
11111,0,0,
-37,-16,38,
-1,0,5,
-5000,5,5000,
-2212,-419,2217,
-4034,-3881,4988,
-3989,-726,3997,
-1580,-1238,1801,
11111,0,0,
11111,0,0,
-1,2,5,
-399,167,389,
-3013,-1766,3203,
-1351,-629,1395,
-1116,816,946,
-758,-428,801,
-86,-77,103,
11111,0,0,
11111,0,0,
-139,104,116,
-7,-3,8,
11111,0,0,
-2746,-2552,3342,
-8,-7,10,
-327,-263,376,
-2366,1528,2131,
11111,0,0,
11111,0,0,
-367,260,317,
-463,215,447,
-805,486,741,
-3736,-695,3744,
-2135,-516,2145,
-3693,-1049,3721,
11111,0,0,
11111,0,0,
11111,0,0,
-1534,383,1526,
-3874,-1654,3972,
-4767,-2476,4980,
-4125,-1417,4180,
-3423,-2943,4033,
-66,-59,79,
11111,0,0,
11111,0,0,
11111,0,0,
-802,-574,890,
-1354,-1012,1521,
-3834,-2149,4047,
-1328,891,1178,
11111,0,0,
11111,0,0,
-335,-170,349,
11111,0,0,
11111,0,0,
-1168,-160,1169,
-13,-10,15,
-2839,1503,2691,
11111,0,0,
-4874,974,4861,
-90,-29,91,
-4889,976,4876,
11111,0,0,
11111,0,0,
-4,5,5,
-1885,-1092,2000,
-1639,318,1635,
-1702,-1403,1974,
-4812,-593,4815,
-377,-215,399,
-20,16,16,
11111,0,0,
11111,0,0,
11111,0,0,
-1057,-579,1112,
-2867,-1606,3026,
-3752,-1347,3809,
-2208,508,2199,
-2318,-638,2334,
};
ll qq[210][3];
ll check(ll t)
{
ll l=-5000,r=5000,res=INF;
while(l<=r)
{
ll mid=l+r>>1;
ll tmp=mid*mid*mid;
if(tmp==t) return mid;
if(tmp>t) r=mid-1;
else l=mid+1;
}
return res;
}
int main()
{
int t;
//init();
/* for(ll x=0;x<=200;++x)
{
ll c=INF;
for(ll i=-5000;i<=5000;++i)
{
for(ll j=-5000;j<=5000;++j)
{
ll t=x-i*i*i-j*j*j;
c=check(t);
if( abs(c)<=5000)
{
printf("%lld,%lld,%lld,\n",i,j,c);
break;
}
}
if( abs(c)<=5000) break;
}
if( abs(c)<=5000) continue;
else printf("11111,0,0,\n");
}*/
cin>>t;
while(t--)
{
int x;
cin>>x;
if(ans[x][0]==11111) cout<<"impossible"<<endl;
else cout<<ans[x][0]<<' '<<ans[x][1]<<' '<<ans[x][2]<<endl;
}
return 0;
}