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的更多相关文章
随机推荐
- 计算n的阶乘
题目描述 定义一个函数,传入一个整数n,打印n!的值比如:传入3打印:6 <====1*2*3 输入 整数n 输出 整数n的阶乘 样例输入 Copy 3 样例输出 Copy 6 x=in ...
- 手动滑稽之golang-vmware-driver广告篇
本来在Windows 7 + Tiny Linux 4.19 + XFS + Vmware Workstation 15 (PRO) 下篇dockerの奥义之后的UEFI补完延迟了... 虽然用efi ...
- 抽象工厂模式(C++)
#include <iostream> using namespace std; class Fruit { public: ; }; class AbstractFactory { pu ...
- Oracle索引大全
文档结构如下: 前言: Oracle 官方文档对索引的描述真是弱透了,对索引的说明就是一坨……,support也没有很好的资料,下面还是用的官方上的内容经过自己的整理加上网上的资料. 索引类型: 索引 ...
- mysql复习2
-- 1. 创建和管理表 CREATE TABLE -- 方式一:CREATE TABLE emp1( id INT(10), `name` VARCHAR(20), salary DOUBLE(10 ...
- css选择器用法,使用css定位元素,css和xpath元素定位的区别
css定位元素 1.什么是css? CSS(Cascading Style Sheets)层叠样式表,是一种语言,用来描述html或者xml的显示样式.在css语言中有css选择器,在selenium ...
- pymysql总结
一.创建数据库 import pymysql conn = pymysql.connect(host='ip', user='root', password='密码') # 以字典的形式返回操作结果 ...
- redis 支持事务
pipe = conn.pipeline(transaction=True) pipe.multi() pipe.set(') pipe.hset('k3','n1',666) pipe.lpush( ...
- maven常用的远程仓库地址
<mirror> <id>nexus-aliyun</id> <name>Nexus aliyun</name> <url>ht ...
- Mysql一分钟定位 Next-Key Lock,你需要几分钟
连接与线程 查看连接信息 show processlist +----+------+------------------+------+---------+------+----------+--- ...