题目编号:4090~4099
外来题解1:
外来题解2:
B:
以下题解来源于鲁东大学,表示感谢!
网盘链接:?
提取码:2nag
A:
AC代码:
1 #include2 #include 3 #include 4 #include 5 #include 6 #include 7 #include
B
AC代码:
1 import java.math.BigInteger; 2 import java.util.Scanner; 3 4 public class Main { 5 6 static Scanner cin = new Scanner(System.in); 7 static BigInteger e,base; 8 static BigInteger zero=BigInteger.valueOf(0); 9 static BigInteger one=BigInteger.valueOf(1);10 static BigInteger two=BigInteger.valueOf(2);11 public static void main(String[] args) {12 13 int test;14 while(cin.hasNext()) {15 test=cin.nextInt();16 for(int i=1;i <= test;++i) {17 18 e=cin.nextBigInteger();19 Solve();20 }21 }22 }23 private static void Solve() {24 25 base=one;26 while(base.multiply(two).compareTo(e) <= 0)27 base=base.multiply(two);28 // System.out.println(base);29 BigInteger ans=base.subtract(one);30 31 if(!base.equals(e))32 ans=ans.add(F());33 System.out.println(ans);34 }35 private static BigInteger F() {36 37 BigInteger curBase=two;38 BigInteger ans=zero;39 BigInteger l=base.divide(curBase);40 BigInteger r=e.divide(curBase);41 for(int i=1;i < 4000;++i) {42 43 if(l.compareTo(r) >= 0)44 break;45 BigInteger tmp=(r.subtract(l)).divide(two);46 if(r.mod(two).intValue() != 0)47 tmp=tmp.add(one);48 ans=ans.add(tmp.multiply(BigInteger.valueOf(i)));49 50 l=l.divide(two);51 r=r.divide(two);52 }53 return ans;54 }55 }
C
AC代码:
1 #include2 #define ll long long 3 #define inf 0x3f3f3f3f 4 #define rep(i,a,b) for(register int i=(a);i<=(b);i++) 5 using namespace std; 6 const int maxn=2010; 7 int n,m,A,B; 8 ll K; 9 int a[maxn],tt[maxn][maxn],sta,pos;10 int ans;11 char s[maxn][maxn];12 char ss[maxn];13 int fg;14 int cal(int i,int j)15 {16 return 81*tt[i][j]+27*tt[i-1][j]+9*tt[i+1][j]+3*tt[i][j-1]+tt[i][j+1];17 }18 int ok[maxn][maxn];19 void bfs()20 {21 ans=0;22 ll t=1;23 int num=0;24 int x=A,y=B;25 while(t<=K)26 {27 t++;28 if(tt[x][y]==1) break;29 int pos=cal(x,y);30 if(ss[pos]=='I') continue;31 else if(ss[pos]=='P')32 {33 if(tt[x][y]==2)34 {35 tt[x][y]=0;36 num++;37 }38 }39 else if(ss[pos]=='U') x--;40 else if(ss[pos]=='D') x++;41 else if(ss[pos]=='L') y--;42 else if(ss[pos]=='R') y++;43 }44 ans=num;45 }46 int main()47 {48 int T,cas=1;49 scanf("%d",&T);50 while(T--)51 {52 scanf("%d%d",&n,&m);53 scanf("%d%d%lld",&A,&B,&K);54 scanf("%s",ss);55 rep(i,1,n)56 scanf("%s",s[i]+1);57 memset(tt,0,sizeof(tt));58 rep(i,1,n)59 rep(j,1,m)60 tt[i][j]=(s[i][j]&15);61 K=min(K,((ll)n*(ll)n*(ll)m*(ll)m));62 bfs();63 printf("%d\n",ans);64 //if(fg) puts("Yes"); else puts("No");65 }66 return 0;67 }
E
AC代码:
1 #include2 #include 3 #include 4 using namespace std; 5 int a[100010],b[100010]; 6 int main(){ 7 int n,k,T,i,x,cnta,cntb; 8 a[0]=0;b[0]=0; 9 cin>>T;10 while(T--){11 cnta=1;cntb=1;12 scanf("%d%d",&n,&k);13 for(i=0;i 0){16 a[cnta]=x;17 cnta++;18 }//分别统计左边和右边各有多少个 19 else if(x<0){20 b[cntb]=-x;21 cntb++;22 }23 }24 25 cnta--;26 cntb--;27 28 sort(a+1,a+cnta+1);29 sort(b+1,b+cntb+1);30 31 //最靠近邮局的几个即使不满足K个也单独送,最近的几个虽然一次送不满,但是距离近,相比于远处的32 //应该让远处的送满,近处的送不满。33 34 long long suma=0;35 for(i=cnta%k;i b[cntb])//两边选不回来的那一趟最小的,让这一趟回来 47 sum=suma+sumb+b[cntb];48 else49 sum=suma+sumb+a[cnta];50 51 printf("%lld\n",sum);52 }53 return 0;54 55 }
H
AC代码:
1 #include2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 #include 10 #include 11 #include 12 #include 13 #include
14 #include