当前位置:网站首页>2022 Hangzhou Electric Multi-School 1st Game
2022 Hangzhou Electric Multi-School 1st Game
2022-07-30 09:20:00 【snuonuo】
A
B. Dragon slayer
题意
思路
代码
C. Backpack
- 题意
Find what is the maximum XOR sum of the values of all items that just fill the backpack,不存在输出-1. - 思路
Is a backpack model,Three dimensions can be considereddp, d p [ i , j , k ] dp[i,j,k] dp[i,j,k]表示前 i i i个物品,异或和是 j j j,The occupied volume is exactly k k k的方案是否存在.Obviously, the state transition is a simple choice or no choice, which can be transferred: d p [ i , j , k ] = d p [ i , j , k ] ∣ d p [ i , j ⊕ w , k − v ] dp[i,j,k]=dp[i,j,k]\ | \ dp[i,j \oplus w,k-v] dp[i,j,k]=dp[i,j,k] ∣ dp[i,j⊕w,k−v].其中, x = a ⊕ b x=a \oplus b x=a⊕b,已知 x x x和 a a a求b,则有 b = a ⊕ x b=a \oplus x b=a⊕x.这个代码如下,会TLE.
while(t--)
{
scanf("%d%d",&n,&m);
for(int i=0;i<=1024;i++) for(int j=0;j<=1024;j++) f[i][j]=0;
f[0][0]=1;
for(int i=1;i<=n;i++)
{
scanf("%d%d",&v,&w);
f[w][v]=1;
for(int j=0;j<1024;j++)
{
for(int k=v;k<=m;k++)
f[j][k]|=f[j^w][k-v];
}
}
int ans=-1;
for(int i=0;i<1024;i++) if(f[i][m]) ans=i;
cout<<ans<<endl;
}
于是考虑使用bitsetPress position,The layer of the cycle volume is optimized away,代码如下:
- 代码
#include<bits/stdc++.h>
using namespace std;
#define N 1050
int n,m,t,x,y;
bitset<N> f[N],g[N];
int main()
{
cin>>t;
while(t--)
{
scanf("%d%d",&n,&m);
for(int j=0;j<1024;++j) f[j].reset();
f[0][0]=1;
for(int i=1;i<=n;++i)
{
cin>>x>>y;
for(int j=0;j<1024;++j)
{
g[j]=f[j];
g[j]<<=x;
}
for(int j=0;j<1024;++j)
{
f[j]|=g[j^y];
}
}
int ans=-1;
for(int i=0;i<1024;i++) if(f[i][m]) ans=i;
cout<<ans<<endl;
}
return 0;
}
D
E
F
G
H
I. Laser
- 题意
给定nThe coordinates of the enemy ( x i , y i ) (x_i,y_i) (xi,yi),There is now a laser transmitter,他可以向8个方向(东、南、西、北、西北、东北、西南、东南)Launch self-centered8条射线.Ask if there is a point that can be placed this laser transmitter,Makes him kill all enemies with one shot. - 思路
Assume any pointQon a horizontal line,Find a point arbitrarilyPnot on this horizontal line.Then the launch center must be at the pointQcentered“米”word and dotPon the three intersections of the straight lines.Then just enumerate those three intersections, O ( n ) O(n) O(n)Determine if you can kill all enemies.
同理,Assume any pointQon a vertical line/主对角线上/副对角线上,Repeat the above operation4次即可,为了方便实现,We rotate the coordinates,Rotate all lines to horizontal in this case. - 代码
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define N 500010
int t,n;
ll a[N],b[N],x[N],y[N];
bool work(ll xx,ll yy)
{
for(int i=1;i<=n;i++)
if(!(x[i]==xx || y[i]==yy || yy-xx==y[i]-x[i] || yy+xx==y[i]+x[i]))
return false;
return true;
}
bool check()
{
int p=0;
for(int i=2;i<=n;i++)
{
if(x[i]==x[1]) continue;
p=1;
if(work(x[1],y[i])) return true; //Note that here is finding a point that is not on this line Do it at this point“米”The intersection of the word and the original determined line.
if(work(x[1],y[i]-(x[i]-x[1]))) return true;
if(work(x[1],y[i]+(x[i]-x[1]))) return true;
break;
}
if(p==0) return true; //Note the points that are specially judged on a line
return false;
}
int main()
{
cin>>t;
while(t--)
{
scanf("%d",&n);
for(int i=1;i<=n;i++)scanf("%lld%lld",&a[i],&b[i]);
bool is_ok=false;
for(int i=1;i<=n;i++)x[i]=a[i],y[i]=b[i];
if(check()) is_ok=true;
for(int i=1;i<=n;i++)x[i]=b[i],y[i]=a[i];
if(check()) is_ok=true;
for(int i=1;i<=n;i++)x[i]=a[i]+b[i],y[i]=a[i]-b[i];
if(check()) is_ok=true;
for(int i=1;i<=n;i++)x[i]=a[i]-b[i],y[i]=a[i]+b[i];
if(check()) is_ok=true;
if(is_ok) printf("YES\n");
else printf("NO\n");
}
return 0;
}
J
K. Random
- 题意
给定n个分布在 [ 0 , 1 ] [0,1] [0,1]之间的数,现在有m次操作,每次操作有 1 / 2 1/2 1/2The probability of removing the smallest of all numbers now,有 1 / 2 1/2 1/2The probability of removing the current largest number among all numbers.Ask what the expectation is for the sum of the last remaining numbers(答案mod1e9+7). - 思路
after each operationnThe probability of the number remaining at a position(A few more observations will reveal that it is n − m n-m n−m),Finally add these probabilities together and multiply 1 / 2 1/2 1/2(The expected value of each number is 1 / 2 1/2 1/2),Because of the modulo operation,Hence the need to use an inverse. - 代码
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll mod =1e9+7;
ll n,m,t;
ll qmi(ll a, ll k, ll p)
{
ll res = 1;
while (k)
{
if (k & 1) res = (ll)res * a % p;
a = (ll)a * a % p;
k >>= 1;
}
return res%p;
}
int main()
{
cin>>t;
while(t--)
{
cin>>n>>m;
if(n==m) printf("0\n");
else
{
if(m==0) printf("%lld\n",(n*qmi(2,mod-2,mod))%mod);
else
{
printf("%lld\n",((n-m)%mod*qmi(2,mod-2,mod))%mod);
}
}
}
return 0;
}
L. Alice and Bob
- 题意
There are many numbers on the blackboard,范围是0-n之间.Alice和Bob玩游戏,AliceDivide the numbers on the blackboard into two sets at a time.BobDelete one of the collections at a time,Subtract one from each number in the other set.当出现一个0时,Alice Win;When all numbers are removedBob Win.Both are extremely smart,现给定0-n每个数的个数,Ask who is the lastWin. - 思路
Observation found that there should be2个1,4个2,8个3…The first mover wins.Two large numbers can be turned into a small one.因此循环a[i]+=a[i+1]/2.最后判断a[0]是否大于1即可. - 代码
#include<bits/stdc++.h>
using namespace std;
#define N 1000010
int t,a[N],n;
int main()
{
cin>>t;
while(t--)
{
scanf("%d",&n);
for(int i=0;i<=n;i++) scanf("%d",&a[i]);
for(int i=n;i>=1;i--) a[i-1]+=a[i]/2;
if(a[0]>0) printf("Alice\n");
else printf("Bob\n");
}
return 0;
}
边栏推荐
- js currying
- It is said that FPGA is high-end, what can it do?
- Apache DolphinScheduler新一代分布式工作流任务调度平台实战-上
- [Unity]UI切换环形滚动效果
- Leetcode - 990: equations of satisfiability
- 怎么在本地电脑上运行dist文件
- The sword refers to offer 48: the longest non-repeating substring
- typescript6 - simplify the steps to run ts
- [Mini Program Column] Summarize the development specifications of uniapp to develop small programs
- 用示波器揭示以太网传输机制
猜你喜欢
![ES报错处理-mapper [xx.xx] of different type, current_type [text], merged_type [keyword]](/img/48/064348ec4d7c2a4fa6ffe7a4778ced.png)
ES报错处理-mapper [xx.xx] of different type, current_type [text], merged_type [keyword]

分布式系统大势所趋,银行运维如何与时俱进?

【愚公系列】2022年07月 Go教学课程 021-Go容器之切片操作

看完这100个客户需求,我终于知道企业文档管理的秘密

【无标题】

SRAM与DRAM的区别

涛思 TDengine 2.6+优化参数

HashSet and LinkedHashSet

ACL 2022 | 引入角度margin构建对比学习目标,增强文本语义判别能力
![[Fun BLDC series with zero basics] Taking GD32F30x as an example, the timer related functions are explained in detail](/img/1d/700c79a766f115d5d0f3bd8263d67c.png)
[Fun BLDC series with zero basics] Taking GD32F30x as an example, the timer related functions are explained in detail
随机推荐
EMC过不了?都是PCB工程师的锅?
jdbc ResultSetMetaData获取tableName问题
Field interpretation under "Surgical variables (RX SUMM-SURG OTH REG/DIS)" in SEER database
cmd命令
R安装包出现error in rawtochar(block[seq_len(ns)]) :
test2
stugc_paper
阿里云国际版云服务器防火墙设置
sql注入数据库原理详解
input标签的tabindex属性 & a标签的tabindex属性
Detailed explanation of 4D words: C language three-point chess advanced + N-piece chess recursive dynamic judgment of winning or losing
【零基础玩转BLDC系列】以GD32F30x为例定时器相关功能详解
如何使用 Jmeter 进行抢购、秒杀等场景下,进行高并发?
typescript5-编译和安装ts代码
test111
DDR、GDDR、QDR的区别
JS中对事件流的理解
typescript6 - simplify the steps to run ts
typescript8 - type annotations
桌面软件开发框架大赏