• AtCoder Beginner Contest 322


    A - First ABC 2

    AC代码:

    1. #include
    2. #define endl '\n'
    3. //#define int long long
    4. using namespace std;
    5. int n;
    6. string s;
    7. void solve() {
    8. cin>>n>>s;
    9. s=' '+s;
    10. for(int i=1;i<=n-2;i++){
    11. if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C'){
    12. cout<
    13. return;
    14. }
    15. }
    16. cout<<-1<
    17. }
    18. int main() {
    19. ios::sync_with_stdio(false);
    20. cin.tie(0);
    21. cout.tie(0);
    22. int t=1;
    23. // cin>>t;
    24. while(t--) {
    25. solve();
    26. }
    27. return 0;
    28. }

    B - Prefix and Suffix

    AC代码:

    1. #include
    2. #define endl '\n'
    3. //#define int long long
    4. using namespace std;
    5. int n,m;
    6. string s,t;
    7. void solve() {
    8. cin>>n>>m;
    9. cin>>s>>t;
    10. bool ok1=true;
    11. for(int i=0,j=0;i
    12. if(s[i]!=t[j++]){
    13. ok1=false;
    14. break;
    15. }
    16. }
    17. bool ok2=true;
    18. for(int i=n-1,j=m-1;i>=0;i--){
    19. if(s[i]!=t[j--]){
    20. ok2=false;
    21. break;
    22. }
    23. }
    24. if(ok1&&ok2) cout<<0<
    25. else if(ok1&&!ok2) cout<<1<
    26. else if(!ok1&&ok2) cout<<2<
    27. else cout<<3<
    28. }
    29. int main() {
    30. ios::sync_with_stdio(false);
    31. cin.tie(0);
    32. cout.tie(0);
    33. int t=1;
    34. // cin>>t;
    35. while(t--) {
    36. solve();
    37. }
    38. return 0;
    39. }

    C - Festival

    AC代码:

    1. #include
    2. #define endl '\n'
    3. //#define int long long
    4. using namespace std;
    5. const int N=2e5+10;
    6. int a[N];
    7. int n,m;
    8. void solve() {
    9. cin>>n>>m;
    10. for(int i=1;i<=m;i++) cin>>a[i];
    11. for(int i=1;i<=n;i++){
    12. int id=lower_bound(a+1,a+1+m,i)-a;
    13. cout<
    14. }
    15. }
    16. int main() {
    17. ios::sync_with_stdio(false);
    18. cin.tie(0);
    19. cout.tie(0);
    20. int t=1;
    21. // cin>>t;
    22. while(t--) {
    23. solve();
    24. }
    25. return 0;
    26. }

    D - Polyomino

    暴力

    图形的旋转平移

    枚举三个图案旋转平移的所有情况,通过状态压缩,转化为一个二进制串,0~15位,如果该格为#,那么就为1

    三个图案的二进制串按位或,如果等于2^(SIZE*SIZE)-1,那么说明三个图案把正方形填满了,如果任意两个图案二进制串按位与不等于0,那么说明图案有重叠

    AC代码:

    1. #include
    2. #define SIZE 4
    3. #define endl '\n'
    4. //#define int long long
    5. using namespace std;
    6. //逆时针旋转90度
    7. void rotate(string s[]){
    8. char temp[SIZE][SIZE];//中间变量
    9. for(int i=0;i
    10. for(int j=0;j
    11. temp[SIZE-j-1][i]=s[i][j];
    12. }
    13. }
    14. for(int i=0;i
    15. for(int j=0;j
    16. s[i][j]=temp[i][j];
    17. }
    18. }
    19. }
    20. //判断合法性
    21. bool valid(int x){
    22. return x>=0&&x
    23. }
    24. //平移
    25. int get(string s[],int dx,int dy){
    26. int ret=0;//ret存储二进制串
    27. for(int x=0;x
    28. for(int y=0;y
    29. if(s[x][y]=='#'){
    30. int tx=x+dx;
    31. int ty=y+dy;
    32. if(!valid(tx)||!valid(ty)) return -1;
    33. ret|=1<<(tx*4+ty);
    34. }
    35. }
    36. }
    37. return ret;//返回图案所对应的二进制串
    38. }
    39. vector<int>add(int id){
    40. vector<int>ret;
    41. string s[SIZE];
    42. for(int i=0;i>s[i];
    43. for(int i=0;i<4;i++){
    44. for(int dx=-3;dx<=3;dx++){
    45. for(int dy=-3;dy<=3;dy++){
    46. int v=get(s,dx,dy);
    47. if(v>=0) ret.push_back(v);
    48. }
    49. }
    50. rotate(s);
    51. }
    52. return ret;
    53. }
    54. void solve() {
    55. vector<int>mask[3];
    56. for(int id=0;id<3;id++) mask[id]=add(id);
    57. for(int x:mask[0]){
    58. for(int y:mask[1]){
    59. for(int z:mask[2]){
    60. if((x|y|z)!=(1<-1) continue;
    61. if(x&y) continue;
    62. if(x&z) continue;
    63. if(y&z) continue;
    64. cout<<"Yes"<
    65. return;
    66. }
    67. }
    68. }
    69. cout<<"No"<
    70. }
    71. int main() {
    72. ios::sync_with_stdio(false);
    73. cin.tie(0);
    74. cout.tie(0);
    75. int t=1;
    76. // cin>>t;
    77. while(t--) {
    78. solve();
    79. }
    80. return 0;
    81. }
  • 相关阅读:
    1个月时间整理了2019年上千道Java面试题,近500页文档!
    猿创征文 |【Linux】常用命令
    【数据结构】栈和队列的模拟实现
    计算机网络--应用层(https)
    【Java】Netty创建网络服务端客户端(TCP/UDP)
    mq学习方式
    网络吞吐量 公网带宽有关吗?
    时间序列问题案例分析Kaggle M5 Forecasting
    Redis主从复制、哨兵以及Cluster集群
    企业数据挖掘平台产品特色及合作案例介绍
  • 原文地址:https://blog.csdn.net/m0_74087709/article/details/133517065