首页 > 其他分享 >atcoder beginer 347 (abc347) D E 题解

atcoder beginer 347 (abc347) D E 题解

时间:2024-04-12 20:33:21浏览次数:14  
标签:atcoder cnt const 题解 LL long 347 maxn include

 

D

就是二进制下,哪些位置有重合(两个1),哪些位置没有重合(1个1,1个0),剩下的都是0。

xor的结果<2^60,就是小于60位(二进制下)。注意要有要求两个数需要是2^60,于是要有大小的判断,因为有的a,b会2^60,但是按照题目要求,这个情况不行。

比如xor的结果,60位都是1,然后a、b各有60个1,那么需要有30个1重合,然后a、b的最高位数是90。

比如xor的结果,是1后面59个0,a、b各有30、31个1,那么有30个1重合,然后a、b的最高位数是61(这个是比较特殊的样例,a的位数+b的位数-xor的位数<60但,xor的位数却大于60)。

另外,调试,也可以用assert(rx<(1ll<<60));的方式。

 

  1 #include <cstdio>
  2 #include <cstdlib>
  3 #include <cstring>
  4 #include <cmath>
  5 #include <cstdbool>
  6 #include <string>
  7 #include <algorithm>
  8 #include <iostream>
  9 #include <sstream>
 10 #include <ctime>
 11 #include <stack>
 12 #include <vector>
 13 #include <queue>
 14 #include <set>
 15 #include <map>
 16 #include <array>
 17 #include <assert.h>
 18 using namespace std;
 19 #define LL long long
 20 #define ULL unsigned long long
 21 
 22 const LL mod_1=1e9+7;
 23 const LL mod_2=998244353;
 24 
 25 const double eps_1=1e-5;
 26 const double eps_2=1e-10;
 27 
 28 const int maxn=500;
 29 
 30 
 31 LL w[maxn],x[maxn],y[maxn];
 32 
 33 int main()
 34 {
 35     LL a,b,c,len=0,cnt_one=0,cnt_loop,rx,ry;
 36     LL i;
 37 
 38     cin>>a>>b>>c;
 39 
 40     memset(w,0,sizeof(w));
 41 
 42     while (c)
 43     {
 44         w[len]=c&1;
 45         c=c>>1;
 46         cnt_one+=w[len];
 47         len++;
 48     }
 49 
 50     if (abs(a-b)>cnt_one || a+b<cnt_one || (a+b-cnt_one)%2==1)  // || (a+b-cnt_one>60)
 51     {
 52         cout << "-1";
 53         return 0;
 54     }
 55 
 56     //cout << "-2";
 57     //return 0;
 58 
 59     cnt_loop=(a+b-cnt_one)/2;
 60     a-=cnt_loop;
 61     b-=cnt_loop;
 62 
 63     memset(x,0,sizeof(x));
 64     memset(y,0,sizeof(y));
 65 
 66     for (i=0;i<len;i++)
 67         if (w[i]==1)
 68         {
 69             if (a>0)
 70             {
 71                 x[i]=1;
 72                 a--;
 73             }
 74             else if (b>0)
 75             {
 76                 y[i]=1;
 77                 b--;
 78             }
 79         }
 80 
 81     for (i=0;i<maxn;i++)
 82         if (cnt_loop>0 && x[i]==0 && y[i]==0)
 83         {
 84             x[i]=1;
 85             y[i]=1;
 86             cnt_loop--;
 87         }
 88 
 89     rx=0;
 90     for (i=maxn-1;i>=0;i--)
 91         rx=(rx<<1ll)|x[i];
 92     ry=0;
 93     for (i=maxn-1;i>=0;i--)
 94         ry=(ry<<1ll)|y[i];
 95 
 96 
 97     //assert(rx<(1ll<<60));
 98     //assert(ry<(1ll<<60));
 99 
100     for (i=maxn-1;i>=60;i--)
101         if (x[i]==1 || y[i]==1)
102         {
103             cout << "-1";
104             return 0;
105         }
106 
107     //cout << (1ll<<60) <<endl;   ///要打括号,否则输出160
108 
109     cout<<rx<<" "<<ry<<endl;
110     return 0;
111 }
112 /*
113 
114 3 0 7
115 
116 59 0 1152921504606846975
117 60 0 1152921504606846975
118 
119 1 0 1152921504606846976
120 
121 
122 0 0 1152921504606846976
123 0 60 1152921504606846976
124 60 0 1152921504606846976
125 0 1 1152921504606846976
126 59 0 1152921504606846975
127 
128 0 2 3
129 0 3 88
130 0 4 88
131 */

 

 

E

题目转化为一个数,是从什么时候开始出现,什么时候结束,然后可能有若干个循环。

否则,解法,可能是不是如可持久化这种奇怪的东西……因为一次只变一个数字。

那么多人通过这道题,是应该想一下原因。

 

 1 #include <cstdio>
 2 #include <cstdlib>
 3 #include <cstring>
 4 #include <cmath>
 5 #include <cstdbool>
 6 #include <string>
 7 #include <algorithm>
 8 #include <iostream>
 9 #include <sstream>
10 #include <ctime>
11 #include <stack>
12 #include <vector>
13 #include <queue>
14 #include <set>
15 #include <map>
16 #include <array>
17 using namespace std;
18 #define LL long long
19 #define ULL unsigned long long
20 
21 const LL mod_1=1e9+7;
22 const LL mod_2=998244353;
23 
24 const double eps_1=1e-5;
25 const double eps_2=1e-10;
26 
27 const int maxn=2e5+10;
28 
29 int f[maxn], cnt[maxn];
30 LL total_cnt[maxn], result[maxn];
31 
32 vector<pair<int,int> > vec[maxn];
33 
34 
35 int main()
36 {
37     int n,q,d,ind, number=0,i;
38     scanf("%d%d",&n,&q);
39 
40     for (ind=1;ind<=q;ind++)
41     {
42         scanf("%d",&d);
43 
44         if (f[d]==0)
45         {
46             f[d]=ind;
47             number++;
48             cnt[ind]=number;
49         }
50         else
51         {
52             vec[d].push_back( make_pair(f[d],ind-1) );
53             f[d]=0;
54             number--;
55             cnt[ind]=number;
56         }
57     }
58 
59     for (i=1;i<=n;i++)
60         if (f[i]!=0)
61             vec[i].push_back( make_pair(f[i], q));
62 
63     total_cnt[0]=0;
64     for (i=1;i<=q;i++)
65         total_cnt[i]=total_cnt[i-1]+cnt[i];
66     for (i=1;i<=n;i++)
67     {
68         for (auto pai:vec[i])
69         {
70             result[i] += total_cnt[pai.second] - total_cnt[pai.first-1];
71         }
72     }
73 
74     for (i=1;i<=n;i++)
75     {
76         cout<<result[i];
77         if (i==n)
78             cout<<endl;
79         else
80             cout<<" ";
81     }
82 
83     return 0;
84 }

 

标签:atcoder,cnt,const,题解,LL,long,347,maxn,include
From: https://www.cnblogs.com/cmyg/p/18132039

相关文章

  • atcoder beginer 348 (abc348) D E F 题解
     E非常经典的树上操作(树上DP)。父节点到某个子节点,值是如何变化的。1#include<cstdio>2#include<cstdlib>3#include<cstring>4#include<cmath>5#include<cstdbool>6#include<string>7#include<algorithm>8#include<iost......
  • 2024.4.10华为暑期实习笔试题解尝试1~2
    题目在4.10华为暑期实习笔试题解努力开摆的小鱼2024-04-10T1简单难度,按照题意顺着写就可以n=int(input())#表示计费日志的条数lst=[]#去重后的日志ss=set()#为了去重foriinrange(n):s=tuple(input().split(","))t=s[0]+s[1]+s[2]#......
  • 题解:P10320 勇气(Courage)
    P10320勇气(Courage)推导过程本题是一道数学题,重点是如何推导出正确式子。首先,先特判几个特殊点:当\(n>=2\)且\(x=2\)时,是不存在解的,战斗力无论何时都不会超过\(2^{n}\)。当\(x\)不强化就以大于\(2^{n}\)。当\(x\)第一次强化达到\(x^{2}\)时,大于\(2^{n}\)......
  • P4211 LCA 题解
    前置知识:树剖、差分题意给定一个\(n\)个节点的有根树树,根为\(1\)。有\(m\)个询问,每个询问给定\(l,r,z\),求\(\sum\limits_{i=l}^rdep[\textrm{LCA}(i,z)]\)。其中\(dep[x]\)表示\(x\)的深度,有\(dep[1]=1\)。题解式子中的\(dep\)不太好算,考虑转化成形式化......
  • [题解] [NOIP2011] 聪明的质检员
    [NOIP2011]聪明的质监员题目描述小T是一名质量监督员,最近负责检验一批矿产的质量。这批矿产共有\(n\)个矿石,从\(1\)到\(n\)逐一编号,每个矿石都有自己的重量\(w_i\)以及价值\(v_i\)。检验矿产的流程是:给定\(m\)个区间\([l_i,r_i]\);选出一个参数\(W\);对......
  • Qt程序加载Qt platform plugin 'xcb' 出错问题解决
    1.Qt程序运行环境ubuntu16.04Qt5.12.3Qt可执行程序编译后运行Qt可执行程序后出现报错报错内容:qt.qpa.plugin:CouldnotloadtheQtplatformplugin"xcb"in""eventhoughitwasfound.ThisapplicationfailedtostartbecausenoQtplatformplugincouldbe......
  • [题解][2022江西省程序设计竞赛] Graphic Game
    题目描述Cirno被推荐了一个游戏,她决定今天和大妖精一起玩。最初,有一个包含2×n个顶点和m条边的图。在每一轮中,Cirno和大妖精都必须选择一个不同的顶点。所选顶点的度数必须相同。然后,Cirno和大妖精将从图中移除它们。现在Cirno想知道是否有办法从给定的图中移除所有顶点。如果......
  • AtCoder Beginner Contest 348
    B-FarthestPoint难度:⭐题目大意一个坐标系有x个点,对于每个点找出距离其最远的点;解题思路数据很小,暴力就行;神秘代码#include<bits/stdc++.h>#defineintlonglong#defineIOSios::sync_with_stdio(false);cin.tie(0);cout.tie(0);#defineendl'\n'......
  • windows MySQL报错Packet for query is too large问题解决
    1、报错Cause:com.mysql.cj.jdbc.exceptions.PacketTooBigException:Packetforqueryistoolarge(11,792,709>4,194,304).Youcanchangethisvalueontheserverbysettingthe'max_allowed_packet'variable.出现问题的原因:批量插入数据量过大MySQL根据配置......
  • Cunning Gena 题解
    \(\texttt{ProblemLink}\)简要题意翻译很清楚。思路记\(x_i\)表示第\(i\)个人的花费,\(s_i\)表示第\(i\)个人做题集合,\(k_i\)表示第\(i\)个人需要的显示器。\(m\le20\)且不是计数,考虑dp,发现确实可以做。可以设\(f_i\)表示做题集合为\(i\)时最小花费。易......