标签:space 水题 main bool 否则 isp oid ons for
C题大水题,欧拉筛筛下素数,然后在线处理一下普通素数。
1 #include <bits/stdc++.h> 2 #define ll long long 3 #define scan(i) scanf("%d",&i) 4 #define scanl(i) scanf("%lld",&i) 5 #define scand(i) scanf("%lf",&i) 6 #define pf printf 7 #define f(i,a,b) for(int i=a;i<=b;i++) 8 const int N=1e7; 9 int phi[N+10],prime[N+10],tot,ans; 10 bool mark[N+10]; 11 void getphi() { 12 int i,j; 13 phi[1]=1; 14 for(i=2;i<=N;i++){ 15 if(!mark[i]){ 16 prime[++tot]=i;//筛素数的时候首先会判断i是否是素数。 17 phi[i]=i-1;//当 i 是素数时 phi[i]=i-1 18 } 19 for(j=1;j<=tot;j++){ 20 if(i*prime[j]>N) break; 21 mark[i*prime[j]]=1;//确定i*prime[j]不是素数 22 if(i%prime[j]==0){//接着我们会看prime[j]是否是i的约数 23 phi[i*prime[j]]=phi[i]*prime[j];break; 24 } 25 else phi[i*prime[j]]=phi[i]*(prime[j]-1);//其实这里prime[j]-1就是phi[prime[j]],利用了欧拉函数的积性 26 } 27 } 28 } 29 //调用时,给出getphi();即可,mark[i]是false说明是素数,否则是合数 30 31 bool isPrime(int num) 32 { 33 if (num == 2 || num == 3) 34 { 35 return true; 36 } 37 if (num % 6 != 1 && num % 6 != 5) 38 { 39 return false; 40 } 41 for (int i = 5; i*i <= num; i += 6) 42 { 43 if (num % i == 0 || num % (i+2) == 0) 44 { 45 return false; 46 } 47 } 48 return true; 49 } 50 51 using namespace std; 52 int n,m,T; 53 int l,r; 54 int main() 55 { 56 getphi(); 57 scan(T); 58 f(kk,1,T){ 59 scanf("%d%d",&l,&r); 60 if(r<=1000){ 61 int cnt=0; 62 f(i,l,r){ 63 if(mark[i]==false) cnt++; 64 } 65 if(cnt*3<r-l+1) pf("Yes\n"); 66 else pf("No\n"); 67 } 68 else if(r-l+1>=12){ 69 pf("Yes\n"); 70 } 71 else{ 72 int cnt=0; 73 f(i,l,r){ 74 if(isPrime(i)) cnt++; 75 } 76 if(cnt*3<r-l+1) pf("Yes\n"); 77 else pf("No\n"); 78 } 79 } 80 return 0; 81 }
F题小水题,离线打表O(1)查询。要预处理一下立方数,会快一点。
1 #include <bits/stdc++.h> 2 #define ll long long 3 #define scan(i) scanf("%d",&i) 4 #define scanl(i) scanf("%lld",&i) 5 #define scand(i) scanf("%lf",&i) 6 #define pf printf 7 #define f(i,a,b) for(int i=a;i<=b;i++) 8 const double eps=1e-8; 9 using namespace std; 10 int ans[604]={ 11 0,0,0, 12 0,0,1, 13 0,1,1, 14 1,1,1, 15 -5001,0,0, 16 -5001,0,0, 17 -1,-1,2, 18 0,-1,2, 19 0,0,2, 20 0,1,2, 21 1,1,2, 22 297,-641,619, 23 7,-11,10, 24 -5001,0,0, 25 -5001,0,0, 26 2,-1,2, 27 0,2,2, 28 1,2,2, 29 75,-218,215, 30 0,-2,3, 31 1,-2,3, 32 28,-86,85, 33 -5001,0,0, 34 -5001,0,0, 35 2,2,2, 36 1839,-2683,2357, 37 0,-1,3, 38 0,0,3, 39 0,1,3, 40 1,1,3, 41 -5001,0,0, 42 -5001,0,0, 43 -5001,0,0, 44 -5001,0,0, 45 2,-1,3, 46 0,2,3, 47 1,2,3, 48 0,-3,4, 49 1,-3,4, 50 -5001,0,0, 51 -5001,0,0, 52 -5001,0,0, 53 -5001,0,0, 54 2,2,3, 55 -5,-7,8, 56 2,-3,4, 57 3,-2,3, 58 6,-8,7, 59 -2,-2,4, 60 -5001,0,0, 61 -5001,0,0, 62 602,-796,659, 63 -5001,0,0, 64 3,-1,3, 65 0,3,3, 66 1,3,3, 67 0,-2,4, 68 1,-2,4, 69 -5001,0,0, 70 -5001,0,0, 71 -1,-4,5, 72 0,-4,5, 73 2,3,3, 74 0,-1,4, 75 0,0,4, 76 0,1,4, 77 1,1,4, 78 -5001,0,0, 79 -5001,0,0, 80 2,-4,5, 81 11,-21,20, 82 2,-1,4, 83 0,2,4, 84 1,2,4, 85 -5001,0,0, 86 -5001,0,0, 87 -5001,0,0, 88 -5001,0,0, 89 26,-55,53, 90 -19,-33,35, 91 2,2,4, 92 3,3,3, 93 847,-1317,1188, 94 3,-2,4, 95 -5001,0,0, 96 -5001,0,0, 97 -5001,0,0, 98 -1972,-4126,4271, 99 3,-4,5, 100 6,-7,6, 101 3,-1,4, 102 0,3,4, 103 1,3,4, 104 -5,-5,7, 105 -5001,0,0, 106 -5001,0,0, 107 14,-22,20, 108 17,-22,18, 109 0,-3,5, 110 2,3,4, 111 -3,-6,7, 112 4,-3,4, 113 118,-239,229, 114 -5001,0,0, 115 -5001,0,0, 116 -4,-7,8, 117 2,-3,5, 118 947,-1309,1117, 119 -948,-1165,1345, 120 146,-1019,1018, 121 -5001,0,0, 122 148,-1040,1039, 123 -5001,0,0, 124 -5001,0,0, 125 -5001,0,0, 126 8,-12,11, 127 -1,-2,5, 128 0,-2,5, 129 3,3,4, 130 -2,-6,7, 131 4,-2,4, 132 -5001,0,0, 133 -5001,0,0, 134 -1,-1,5, 135 0,-1,5, 136 0,0,5, 137 0,1,5, 138 1,1,5, 139 0,4,4, 140 1,4,4, 141 -5001,0,0, 142 -5001,0,0, 143 2,-1,5, 144 0,2,5, 145 1,2,5, 146 2,-6,7, 147 2,4,4, 148 -9,-11,13, 149 -77,-86,103, 150 -5001,0,0, 151 -5001,0,0, 152 2,2,5, 153 -3,-7,8, 154 -5001,0,0, 155 3,-2,5, 156 -7,-8,10, 157 108,-149,127, 158 1528,-2366,2131, 159 -5001,0,0, 160 -5001,0,0, 161 260,-367,317, 162 3,-1,5, 163 0,3,5, 164 1,3,5, 165 3,-6,7, 166 3,4,4, 167 -5001,0,0, 168 -5001,0,0, 169 -5001,0,0, 170 80,-130,119, 171 2,3,5, 172 20,-31,28, 173 4,-3,5, 174 226,-1134,1131, 175 -45,-47,58, 176 -5001,0,0, 177 -5001,0,0, 178 -5001,0,0, 179 56,-172,170, 180 0,-7,8, 181 1,-7,8, 182 67,-87,71, 183 -5001,0,0, 184 -5001,0,0, 185 7,-8,7, 186 -5001,0,0, 187 -5001,0,0, 188 2,-7,8, 189 -10,-13,15, 190 3,3,5, 191 -5001,0,0, 192 4,-2,5, 193 9,-14,13, 194 10,-17,16, 195 -5001,0,0, 196 -5001,0,0, 197 5,-4,5, 198 27,-58,56, 199 4,-1,5, 200 0,4,5, 201 1,4,5, 202 4,-6,7, 203 4,4,4, 204 -5001,0,0, 205 -5001,0,0, 206 -5001,0,0, 207 3,-7,8, 208 2,4,5, 209 148,-195,161, 210 15,-24,22, 211 73,-114,103}; 212 int l,r; 213 struct p{ 214 int a;int b;int c; 215 p(){} 216 p(int aa,int bb,int cc){ 217 a=aa; 218 b=bb; 219 c=cc; 220 } 221 }vec[202]; 222 int main() 223 { 224 /*freopen("in.txt","r",stdin); 225 f(i,0,200){ 226 stringstream ss; 227 string s; 228 getline(cin,s); 229 if(s.length()<=2){ 230 cout<<"-5001,0,0,"<<endl; 231 continue; 232 } 233 //scanf("%d",&vec[i].a); 234 ss.str(s); 235 ss>>vec[i].a; 236 //scanf("%d%d",&vec[i].b,&vec[i].c); 237 ss>>vec[i].b>>vec[i].c; 238 cout<<vec[i].a<<","<<vec[i].b<<","<<vec[i].c<<",\n"; 239 }*/ 240 int T,n; 241 scan(T); 242 f(kk,1,T){ 243 scan(n); 244 if(ans[3*n]==-5001){puts("impossible");} 245 else pf("%d %d %d\n",ans[3*n],ans[3*n+1],ans[3*n+2]); 246 } 247 }
A题数论题。已将结论整理在ACM-数论:一些零碎的数论定理中。
1 #include <bits/stdc++.h> 2 #define ll long long 3 #define scan(i) scanf("%d",&i) 4 #define scanl(i) scanf("%lld",&i) 5 #define scand(i) scanf("%lf",&i) 6 #define pf printf 7 #define f(i,a,b) for(int i=a;i<=b;i++) 8 using namespace std; 9 int T; 10 ll l,r,s; 11 ll cal(ll x){ 12 switch(x%4){ 13 case 0:return x; 14 case 1:return 1; 15 case 2:return x+1; 16 case 3:return 0; 17 } 18 } 19 int main() 20 { 21 scan(T); 22 f(kk,1,T){ 23 scanf("%lld%lld%lld",&l,&r,&s); 24 ll lef=(l+1)/2*2; 25 ll m=(lef+3)%4ll; 26 ll rig=(r-m)/4*4+m; 27 //cout<<lef<<" "<<rig<<endl; 28 if(rig>lef){ 29 ll ans=0; 30 ll ansv=rig-lef+1; 31 //ll zuo=lef-l; 32 //ll you=r-rig; 33 for(ll i=lef;i>=l;i--){ 34 ll ans1=ans; 35 for(ll j=rig;j<=r;j++){ 36 //if(i==lef&&j==rig) continue; 37 if(j!=rig) ans1^=j; 38 if(ans1<=s){ 39 ansv=max(ansv,j-i+1); 40 } 41 } 42 ans^=(i-1); 43 } 44 //cout<<ansv<<endl; 45 pf("%lld\n",ansv); 46 } 47 else{ 48 ll ans=-1; 49 //cout<<s<<endl; 50 for(ll i=l;i<=r;i++){ 51 for(ll j=i;j<=r;j++){ 52 if((cal(i-1)^cal(j))<=s){ 53 ans=max(ans,j-i+1); 54 //cout<<i-1<<" "<<j<<" "<<(cal(i-1)^cal(j))<<" "<<s<<endl; 55 } 56 } 57 } 58 //cout<<ans<<endl; 59 pf("%lld\n",ans); 60 } 61 } 62 return 0; 63 }
M题关于树。我一定要学会数据结构中的树,只靠那一点自欺欺人的数论和图论知识是没有办法独当一面的。只有自己才最靠得住。加油啊。
标签:space 水题 main bool 否则 isp oid ons for
原文地址:https://www.cnblogs.com/St-Lovaer/p/12002279.html