Codeforces_812
A. 每条人行道有六条车道会撞到。
#include<bits/stdc++.h>
using namespace std; int a[],b[],c[],d[]; int main()
{
ios::sync_with_stdio();
for(int i = ;i < ;i++) cin >> a[i] >> b[i] >> c[i] >> d[i];
int flag = ;
for(int i = ;i < ;i++)
{
if(!d[i]) continue;
if(a[i] || b[i] || c[i] || a[(i+)%] || b[(i+)%] || c[(i+)%]) flag = ;
}
if(flag) cout << "YES" << endl;
else cout << "NO" << endl;
return ;
}
B.dp,注意最后一层增加的时间不一样。
#include<bits/stdc++.h>
using namespace std; int n,m,dp[][] = {};
string s[]; int main()
{
ios::sync_with_stdio();
cin >> n >> m;
for(int i = ;i <= n;i++)
{
cin >> s[i];
s[i] = " "+s[i];
}
int t;
for(t = ;t <= n;t++)
{
int flag = ;
for(int j = ;j <= m+;j++)
{
if(s[t][j] == '') flag = ;
}
if(flag) break;
}
if(t == n+)
{
cout << << endl;
return ;
}
dp[][n+] = -;
dp[][n+] = 1e9;
for(int i = n;i >= t;i--)
{
int l = m+;
int r = ;
for(int j = m+;j >= ;j--)
{
if(s[i][j] == '') l = j;
}
for(int j = ;j <= m+;j++)
{
if(s[i][j] == '') r = j;
}
if(i == t)
{
cout << min(dp[][i+]+r,dp[][i+]+m+-l) << endl;
return ;
}
dp[][i] = min(dp[][i+]+m+,dp[][i+]+*(r-)+);
dp[][i] = min(dp[][i+]+m+,dp[][i+]+*(m+-l)+);
}
return ;
}
C.二分个数,注意long long。
#include<bits/stdc++.h>
using namespace std; int n,s;
long long a[],b[]; bool ok(int x)
{
for(int i = ;i <= n;i++) b[i] = a[i]+(long long)x*i;
sort(b+,b++n);
long long sum = ;
for(int i = ;i <= x;i++) sum += b[i];
return sum <= s;
}
int main()
{
ios::sync_with_stdio();
cin >> n >> s;
for(int i = ;i <= n;i++) cin >> a[i];
int l = ,r = n;
while(l < r)
{
int mid = (l+r+)/;
if(ok(mid)) l = mid;
else r = mid-;
}
for(int i = ;i <= n;i++) b[i] = a[i]+(long long)l*i;
sort(b+,b++n);
long long sum = ;
for(int i = ;i <= l;i++) sum += b[i];
cout << l << " " << sum << endl;
return ;
}
D.建一个有向图,前面的requests组成的是森林或树,再加一个后,若形成了环,则x和x的子孙都会cry,否则没有人会cry。
对于1e5的queries,我们先预处理每个节点的子孙个数和和dfs序,然后判断就简单了。
#include<bits/stdc++.h>
using namespace std; int n,m,k,q,cnt = ,pre[] = {},l[],r[],ok[] = {},sum[];
vector<int> v[]; void dfs(int now)
{
++cnt;
l[now] = cnt;
sum[now] = ;
for(int i = ;i < v[now].size();i++)
{
int t = v[now][i];
dfs(t);
sum[now] += sum[t];
}
r[now] = cnt;
}
int main()
{
ios::sync_with_stdio();
cin >> n >> m >> k >> q;
while(k--)
{
int x,y;
cin >> x >> y;
if(pre[y] != )
{
v[pre[y]].push_back(x);
ok[x] = ;
}
pre[y] = x;
}
for(int i = ;i <= n;i++)
{
if(!ok[i]) dfs(i);
}
while(q--)
{
int x,y;
cin >> x >> y;
if(pre[y] && l[x] <= l[pre[y]] && r[pre[y]] <= r[x]) cout << sum[x] << endl;
else cout << << endl;
}
return ;
}
E.普通nim游戏判断过程为每堆石子个数的异或。若增加一个可以增加石子的操作,结果相同,因为一个人加的另一个人可以减去相同数量。我们建树,把跟叶子节点向上相差偶数个节点的点作为堆,其余的作为可以增加的石子。那么判断过程为这些堆的异或。ok为0则成立,我们现在要使ok变为0。
根据异或性质,在两类节点之间可以成立的交换操作为ok^a[i]^b[i]==0的两个点。
另外,若ok已经为0,我们可以进行节点同类中交换。
#include<bits/stdc++.h>
using namespace std; int n,a[],h[];
map<int,int> mp;
vector<int> v[]; void dfs(int now)
{
int x = ;
for(int i = ;i < v[now].size();i++)
{
int t = v[now][i];
dfs(t);
x = max(h[t],x);
}
h[now] = x+;
} int main()
{
ios::sync_with_stdio();
cin >> n;
for(int i = ;i <= n;i++) cin >> a[i];
for(int i = ;i <= n;i++)
{
int x;
cin >> x;
v[x].push_back(i);
}
dfs();
int ok = ,cnt1 = ;
for(int i = ;i <= n;i++)
{
if(h[i]%)
{
ok ^= a[i];
cnt1++;
mp[a[i]]++;
}
}
int cnt2 = n-cnt1;
long long ans = ;
if(ok == ) ans = (long long)cnt1*(cnt1-)/+(long long)cnt2*(cnt2-)/;
for(int i = ;i <= n;i++)
{
if(h[i]% == ) ans += mp[ok^a[i]];
}
cout << ans << endl;
return ;
}
Codeforces_812的更多相关文章
随机推荐
- nginx错误: [error] OpenEvent("Global\ngx_reload_10444") failed (2: The system cannot find the file specified)
执行nginx -s reload命令: nginx: [error] OpenEvent("Global\ngx_reload_10444") failed (2: The sy ...
- jenkins +git+ssh 构建 .net项目
jenkins +git+ssh 构建 .net项目 安装jenkins jdk 和插件就不一一介绍了. Multiple SCMs 插件介绍:可以获取多个项目(如果你的项目中有依赖其他项目的) So ...
- MongoDB 上手开发实践(入门上手开发这一篇就够了)
前言 MongoDB是一个介于 关系数据库 和非关系数据库之间的产品,是非关系数据库当中功能最丰富,最像关系数据库的.它支持的数据结构非常松散,是类似 json 的 bson 格式,因此可以存储比较复 ...
- FUTABA舵机参数大全
S9150 Digital servo 尺寸:47.5X27X25.3mm 重量:53g 速度:0.18sec/60"(4.8V) 扭力:5.8kg:cm(4.8V) ——————————— ...
- 【转】Java集合框架面试问题集锦
Java集合框架(例如基本的数据结构)里包含了最常见的Java常见面试问题.很好地理解集合框架,可以帮助你理解和利用Java的一些高级特性.下面是面试Java核心技术的一些很实用的问题. Q:最常见的 ...
- cogs 3008. 朋友圈
3008. 朋友圈 ★★ 输入文件:friendscircle.in 输出文件:friendscircle.out 简单对比时间限制:1 s 内存限制:256 MB [题目描述] NO ...
- 最短路Dijkstra算法模板
// // dijkstra妯℃澘.cpp // algorithm // // Created by david.xu on 2018/8/6. // Copyright 漏 2018骞?david ...
- 逆元(inv)
推荐博客 : http://blog.csdn.net/baidu_35643793/article/details/75268911 通常我们在计算除法取模时,并不能直接的取模后再去相除,答案会有问 ...
- TCP/IP协议与HTTP协议(二)
TCP/IP协议是传输层协议,主要解决数据如何在网络中传输,而HTTP是应用层协议,主要解决如何包装数据. 1.TCP连接 手机能够使用联网功能是因为手机底层实现了TCP/IP协议,可以使手机终端通过 ...
- AI漫谈:我们距离实现《庆余年》里的五竹叔机器人还有多远?
(警告: 本文包含少量剧透内容,请酌情阅读) 五竹叔是机器人吗? 看过庆余年的朋友,一定对五竹叔印象深刻,外表英俊潇洒,一袭黑衣加黑布条蒙眼,充满神秘侠客气息.五竹叔不但神秘,而且言行举止常常很 ...