当前位置:网站首页>NewOJ Week 6
NewOJ Week 6
2022-06-21 19:33:00 【WAWA源】
B 特殊数字—预处理+二分
#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
#define int long long
const int N = 100010;
vector<int>nums;
signed main()
{
for(int i=0;i<=30;i++)
for(int j=i+1;j<=30;j++)
nums.push_back((1<<i)+(1<<j));
sort(nums.begin(),nums.end());
int T;cin>>T;
while(T--)
{
int x;cin>>x;
int res=1e9;
int pos=lower_bound(nums.begin(),nums.end(),x)-nums.begin();
if(nums[pos]==x)res=0;
else
{
res=nums[pos]-x;
if(pos>0)res=min(res,x-nums[pos-1]);
}
cout<<res<<'\n';
}
}
C 质数拼图游戏—BFS
#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
using namespace std;
#define int long long
int dx[4]={
0,1};
int dy[4]={
1,0};
int vis[21]={
0,
0,1,1,0,1,0,1,0,0,0,
1,0,1,0,0,0,1,0,1,0,
};
queue<string>q;
map<string,int>mp;
void bfs(string s)
{
q.push(s);
mp[s]=0;
while(q.size())
{
string t=q.front();
q.pop();
for(int i=0;i<3;i++)for(int j=0;j<3;j++)
{
int x1=i*3+j;
for(int k=0;k<2;k++)
{
int x=i+dx[k];
int y=j+dy[k];
if(x>=3||y>=3)continue;
int x2=x*3+y;
if(vis[t[x1]-'0'+t[x2]-'0'])
{
string ss=t;
swap(ss[x1],ss[x2]);
if(!mp.count(ss))
{
mp[ss]=mp[t]+1;
q.push(ss);
}
}
}
}
}
}
signed main()
{
string s="123456789";
bfs(s);
int T;cin>>T;
while(T--)
{
string ss="";
for(int i=0;i<9;i++)
{
char op;cin>>op;
ss+=op;
}
if(mp.count(ss))cout<<mp[ss]<<'\n';
else cout<<-1<<'\n';
}
}
D 推箱子—差分
#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
#define int long long
const int N=1000010;
int s[N]={
0};
signed main()
{
int n,h;cin>>n>>h;
for(int i=1,l,r;i<=n;i++)
{
cin>>l>>r;
s[l]++;
s[r+1]--;
}
for(int i=1;i<=n;i++)s[i]+=s[i-1];
for(int i=1;i<=n;i++)s[i]+=s[i-1];
int res=1e18;
for(int i=1;i+h-1<=n;i++)
{
int t=s[i+h-1]-s[i-1];
res=min(res,n*h-t);
}
cout<<res<<'\n';
}
E 最小公倍数—数学推导
#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
using namespace std;
#define int long long
const int N=1000010 , INF=1e18;
map<int,pair<int,int>>mp;
void init()
{
for(int l=1;l<=2000000;l++)
{
int sum=l*(l+1);
for(int r=l+2;;r++)
{
int g=__gcd(sum,r);
if(sum/g>INF/r)break;
sum=sum/g*r;
if(!mp.count(sum))
{
mp[sum]={
l,r};
}
}
}
}
void solve()
{
pair<int,int>res;
int n;cin>>n;
int t=(sqrt(4*n+1)-1)/2;
if(t*(t+1)==n)
{
res={
t,t+1};
if(mp.count(n))
{
if(mp[n].first<t)
res=mp[n];
}
}
else if(mp.count(n))res=mp[n];
else
{
cout<<-1<<'\n';
return ;
}
cout<<res.first<<" "<<res.second<<'\n';
}
signed main()
{
init();
int T;cin>>T;
while(T--)solve();
}
边栏推荐
- Unity analog flashlight light source detector, AI attack range detection area, object detection in visual cone, fan-shaped area detection, circular area detection, cone area detection
- Vertical and horizontal network shooting range community Modbus Protocol
- It is said that the price of the iPhone 14 will rise; TikTok US user data is transferred to Oracle, and bytes cannot be accessed; Seatunnel 2.1.2 releases geek headlines
- Golang学习笔记—指针
- LeeCode435 无重叠区间
- 行业首家!极氪APP获中国网络安全审查技术与认证中心权威认证
- 多线程实例代码(demo)
- STL之vector扩容机制
- 十一、美化界面
- MySQL数据库---事务
猜你喜欢

AB打包有的Shader没有触发IPreprocessShaders的回调

纵横网络靶场社区-Modbus协议

The Summer Challenge realizes a standard layout of Huawei app with openharmony ETS

Alibaba cloud ack one and ACK cloud native AI suite have been newly released to meet the needs of the end of the computing era

Adum1401arwz-rl adenault digital signal isolation module

向量与平面交点

Take off, annual salary: 400000+

数据路:三人行,必有我师!

高考后网上查询信息,注意防范没有 SSL证书的网站

Introduction to internet protocol -- five layer model
随机推荐
网关是什么
What is redis hyperloglog? The use of these scenes makes me laugh like a dragon
LeeCode70 爬楼梯
有哪些新手程序员不知道的小技巧?
服务器正文17:内存映射和共享内存的简单理解
Get the openharmony source code: get it from the deveco marketplace (1)
互联网协议入门详解--五层模型
Henkel database custom operator '! ~~'
Golang学习笔记—指针
Adum1401arwz-rl adenault digital signal isolation module
Laravel imports and exports excel using phpoffice
AXI_ Bus_ Matrix_ 4x4 design - logic design
机器学习之数据处理与可视化【鸢尾花数据分类|特征属性比较】
数据路:三人行,必有我师!
The final scheme of adding traceid at the C end
关于SQL Server中变量前加上 N与其他使用情况解析
Take off, annual salary: 400000+
PCA based face recognition system and face pose analysis
【MySQL·水滴计划】第三话- SQL的基本概念
C端添加Traceid的最终的方案