第一次这么顺手。。。都是1A。。。。D想了1个小时,想了一个假算法。。。最后20分开E,我叼,简单DP???不负众望的10分钟A掉。。。

 

A. Yet Another Dividing into Teams 只会有两个队

 B1.B2. Books Exchange直接DFS找环,环内的传递时间是一样的。标记一下,线性复杂度。

 C1. Good Numbers (easy version) 其实就是3进制表示形式不能有2,那么简单版本直接预处理1-1000然后找第一个大于n的数即可。

#include<bits/stdc++.h>
#define LL long long
using namespace std;
vector<int>ans;
bool check(int x){
   int flag=0;
   while(x){
     if (x%3==2){
        flag=1;
        break;
     }
     x=x/3;
   }
   if (flag==1)return 0;
   else return 1;
}
void init(){
  for (int i=1;i<=19683;i++){
     if(check(i)){
        ans.push_back(i);
     }
  }
}
int main(){
  int t,n;
  scanf("%d",&t);
  init();
  while(t--){
     scanf("%d",&n);
     int pos=lower_bound(ans.begin(),ans.end(),n)-ans.begin();
     printf("%d\n",ans[pos]);
  }
  return 0;
}
View Code

相关文章:

  • 2021-07-31
  • 2022-02-14
  • 2021-09-24
  • 2021-11-17
  • 2021-10-29
  • 2021-09-01
  • 2021-04-06
  • 2021-05-01
猜你喜欢
  • 2019-11-06
  • 2022-12-23
  • 2020-05-15
  • 2022-01-15
  • 2021-10-20
  • 2021-10-27
  • 2021-05-17
相关资源
相似解决方案