A - Rooms and Passages

题意:找到每个数后面第一个负正对。

从前往后比较麻烦。从后向前,先记录正数位置,一旦出现这个数的相反数即产生一对负正对,通过和前面的负正对比较更新答案。

view code
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include <queue>
#include<sstream>
#include <stack>
#include <set>
#include <bitset>
#include<vector>
#define FAST ios::sync_with_stdio(false)
#define abs(a) ((a)>=0?(a):-(a))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mem(a,b) memset(a,b,sizeof(a))
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define rep(i,a,n) for(int i=a;i<=n;++i)
#define per(i,n,a) for(int i=n;i>=a;--i)
#define endl '\n'
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
const int maxn = 5e5+200;
const int inf=0x3f3f3f3f;
const double eps = 1e-7;
const double pi=acos(-1.0);
const int mod = 1e9+7;
inline int lowbit(int x){return x&(-x);}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
void ex_gcd(ll a,ll b,ll &d,ll &x,ll &y){if(!b){d=a,x=1,y=0;}else{ex_gcd(b,a%b,d,y,x);y-=x*(a/b);}}//x=(x%(b/d)+(b/d))%(b/d);
inline ll qpow(ll a,ll b,ll MOD=mod){ll res=1;a%=MOD;while(b>0){if(b&1)res=res*a%MOD;a=a*a%MOD;b>>=1;}return res;}
inline ll inv(ll x,ll p){return qpow(x,p-2,p);}
inline ll Jos(ll n,ll k,ll s=1){ll res=0;rep(i,1,n+1) res=(res+k)%i;return (res+s)%n;}
inline ll read(){ ll f = 1; ll x = 0;char ch = getchar();while(ch>'9'||ch<'0') {if(ch=='-') f=-1; ch = getchar();}while(ch>='0'&&ch<='9') x = (x<<3) + (x<<1) + ch - '0', ch = getchar();return x*f; }
int dir[4][2] = { {1,0}, {-1,0},{0,1},{0,-1} }; ll Map[maxn];
ll ans[maxn];
ll a[maxn]; int main()
{
ll n = read();
rep(i,1,n) a[i] = read();
int pre = inf;
per(i,n,1)
{
if(a[i]>0)
{
if(pre==inf) Map[a[i]] = i,ans[i] = n-i+1;
else
{
ans[i] = pre - i;
Map[a[i]] = i;
}
}
else
{
if(!Map[-a[i]])
{
ans[i] = min(pre - i,n - i + 1);
}
else
{
ans[i] = min(Map[-a[i]] - i,pre-i);
pre = min(pre,Map[-a[i]]);
}
}
}
rep(i,1,n) cout<<ans[i]<<' ';cout<<endl;
return 0;
}

B - Rearrange Columns

题意:给你一个\(2*n\)矩阵,只含有#和. , 问你在可以交换任意列的情况下能否使得#联通。

思路:列只有四种情况

1 #和.

2 .和#

3 #和#

4 .和.

只有在3不存在且12同时存在的时候才会NO。

其他情况下就3放中间其他放两边即可。

view code
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include <queue>
#include<sstream>
#include <stack>
#include <set>
#include <bitset>
#include<vector>
#define FAST ios::sync_with_stdio(false)
#define abs(a) ((a)>=0?(a):-(a))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mem(a,b) memset(a,b,sizeof(a))
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define rep(i,a,n) for(int i=a;i<=n;++i)
#define per(i,n,a) for(int i=n;i>=a;--i)
#define endl '\n'
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll; const double eps = 1e-7;
const double pi=acos(-1.0);
const int mod = 1e9+7;
inline int lowbit(int x){return x&(-x);}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
void ex_gcd(ll a,ll b,ll &d,ll &x,ll &y){if(!b){d=a,x=1,y=0;}else{ex_gcd(b,a%b,d,y,x);y-=x*(a/b);}}//x=(x%(b/d)+(b/d))%(b/d);
inline ll qpow(ll a,ll b,ll MOD=mod){ll res=1;a%=MOD;while(b>0){if(b&1)res=res*a%MOD;a=a*a%MOD;b>>=1;}return res;}
inline ll inv(ll x,ll p){return qpow(x,p-2,p);}
inline ll Jos(ll n,ll k,ll s=1){ll res=0;rep(i,1,n+1) res=(res+k)%i;return (res+s)%n;}
inline ll read(){ ll f = 1; ll x = 0;char ch = getchar();while(ch>'9'||ch<'0') {if(ch=='-') f=-1; ch = getchar();}while(ch>='0'&&ch<='9') x = (x<<3) + (x<<1) + ch - '0', ch = getchar();return x*f; }
int dir[4][2] = { {1,0}, {-1,0},{0,1},{0,-1} }; vector<ll> fi_type;
vector<ll> se_type;
vector<ll> th_type;
vector<ll> es_type; int main()
{
char s[3][5000];
char ans[3][5000];
gets(s[1]+1);
gets(s[2]+1);
int len = strlen(s[1]+1);
rep(j,1,len)
{
if(s[1][j]=='#'&&s[2][j]=='#') fi_type.pb(j);
else if(s[1][j]=='#'&&s[2][j]=='.') se_type.pb(j);
else if(s[1][j]=='.'&&s[2][j]=='#') th_type.pb(j);
else es_type.pb(j);
}
if(fi_type.size()==0&&se_type.size()&&th_type.size())
{
cout<<"NO"<<endl;
}
else
{
cout<<"YES"<<endl;
per(j,len,1)
{
if(th_type.size())
{
int cur = th_type[th_type.size()-1];
ans[1][j] = s[1][cur], ans[2][j] = s[2][cur];
th_type.pop_back();
}
else if(fi_type.size())
{
int cur = fi_type[fi_type.size()-1];
ans[1][j] = s[1][cur], ans[2][j] = s[2][cur];
fi_type.pop_back();
}
else if(se_type.size())
{
int cur = se_type[se_type.size()-1];
ans[1][j] = s[1][cur], ans[2][j] = s[2][cur];
se_type.pop_back();
}
else
{
int cur = es_type[es_type.size()-1];
ans[1][j] = s[1][cur], ans[2][j] = s[2][cur];
es_type.pop_back();
} }
rep(i,1,2) rep(j,1,len)
{
cout<<ans[i][j];
if(j==len) cout<<endl;
}
}
return 0;
}

C - Jumps on a Circle

题意:给你一个大小为p,编号从\(0~p-1\)的环,从0开始往前跳,步长从1开始每次增1,问跳了n次后有多少个格子被踩到过。

思路:当前的位置即是

pos = \({{n(n-1)}\over 2}\) \(\%p\)。

当n = 2p时 pos = 0,

当n = 2p+1时, pos = (p(p-1)+2p + 1)%p = 1。

即发现2p为一个循环节。所以总的遍历次数不超过2p,O(2p)遍历一遍就可以了。

view code
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include <queue>
#include<sstream>
#include <stack>
#include <set>
#include <bitset>
#include<vector>
#define FAST ios::sync_with_stdio(false)
#define abs(a) ((a)>=0?(a):-(a))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mem(a,b) memset(a,b,sizeof(a))
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define rep(i,a,n) for(int i=a;i<=n;++i)
#define per(i,n,a) for(int i=n;i>=a;--i)
#define endl '\n'
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PII;
const int maxn = 1e7+200;
const int inf=0x3f3f3f3f;
const double eps = 1e-7;
const double pi=acos(-1.0);
const int mod = 1e9+7;
inline int lowbit(int x){return x&(-x);}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
void ex_gcd(ll a,ll b,ll &d,ll &x,ll &y){if(!b){d=a,x=1,y=0;}else{ex_gcd(b,a%b,d,y,x);y-=x*(a/b);}}//x=(x%(b/d)+(b/d))%(b/d);
inline ll qpow(ll a,ll b,ll MOD=mod){ll res=1;a%=MOD;while(b>0){if(b&1)res=res*a%MOD;a=a*a%MOD;b>>=1;}return res;}
inline ll inv(ll x,ll p){return qpow(x,p-2,p);}
inline ll Jos(ll n,ll k,ll s=1){ll res=0;rep(i,1,n+1) res=(res+k)%i;return (res+s)%n;}
inline ll read(){ ll f = 1; ll x = 0;char ch = getchar();while(ch>'9'||ch<'0') {if(ch=='-') f=-1; ch = getchar();}while(ch>='0'&&ch<='9') x = (x<<3) + (x<<1) + ch - '0', ch = getchar();return x*f; }
int dir[4][2] = { {1,0}, {-1,0},{0,1},{0,-1} }; ll vis[maxn]; int main()
{
ll p = read(), n = read();
n = min(n,2*p+1);
ll cur = 0;
vis[0] = 1;
ll step = 1;
ll ans = 1;
while(n--)
{
cur += step;
cur %= p;
if(!vis[cur]) ans ++;
vis[cur] = 1;
step ++;
}
cout<<ans<<endl;
return 0;
}

J - The Power of the Dark Side - 2

题意:有n个人,每个人有三个属性,如果这个人有两个属性比其他某个人的这两个属性都高,就能打败他。现在可以在攻击的时候调整自身属性,重新分配技能点,问每个人最多能打败多少人。

思路:贪心。肯定是先分配一个0打对方的最高的,自己剩下来的平分给自己两个属性来打对面。所以只用看自己的三者和-2(至少比对方最小两个都大1)能否大于等于对方的两个最小的和,外层遍历n个人,内层二分即可。

view code
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include <queue>
#include<sstream>
#include <stack>
#include <set>
#include <bitset>
#include<vector>
#define FAST ios::sync_with_stdio(false)
#define abs(a) ((a)>=0?(a):-(a))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mem(a,b) memset(a,b,sizeof(a))
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define rep(i,a,n) for(int i=a;i<=n;++i)
#define per(i,n,a) for(int i=n;i>=a;--i)
#define endl '\n'
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
const int maxn = 5e5+200;
const int inf=0x3f3f3f3f;
const double eps = 1e-7;
const double pi=acos(-1.0);
const int mod = 1e9+7;
inline int lowbit(int x){return x&(-x);}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
void ex_gcd(ll a,ll b,ll &d,ll &x,ll &y){if(!b){d=a,x=1,y=0;}else{ex_gcd(b,a%b,d,y,x);y-=x*(a/b);}}//x=(x%(b/d)+(b/d))%(b/d);
inline ll qpow(ll a,ll b,ll MOD=mod){ll res=1;a%=MOD;while(b>0){if(b&1)res=res*a%MOD;a=a*a%MOD;b>>=1;}return res;}
inline ll inv(ll x,ll p){return qpow(x,p-2,p);}
inline ll Jos(ll n,ll k,ll s=1){ll res=0;rep(i,1,n+1) res=(res+k)%i;return (res+s)%n;}
inline ll read(){ ll f = 1; ll x = 0;char ch = getchar();while(ch>'9'||ch<'0') {if(ch=='-') f=-1; ch = getchar();}while(ch>='0'&&ch<='9') x = (x<<3) + (x<<1) + ch - '0', ch = getchar();return x*f; }
int dir[4][2] = { {1,0}, {-1,0},{0,1},{0,-1} }; typedef struct Information
{
ll sum2;
ll sum3;
ll id;
Information(){}
Information(ll a, ll b): sum2(a), sum3(b){}
bool operator< (const Information& a)
{
if(sum2!=a.sum2)
return sum2 < a.sum2;
return sum3 < a.sum3;
}
}I;
I a[maxn];
ll Ans[maxn];
ll Map[maxn]; int main()
{
ll n = read();
rep(i,1,n)
{
ll b[5];
b[1] = read(), b[2] = read(), b[3] = read();
sort(b+1,b+1+3);
a[i].sum2 = b[1] + b[2];
a[i].sum3 = b[1] + b[2] + b[3];
a[i].id = i;
}
sort(a+1,a+1+n);
ll ans = 0;
a[n+1].sum2 = 1e15;
rep(i,1,n)
{
int idx = lower_bound(a+1,a+1+n,Information(a[i].sum3-2,1e15)) - a;
if(idx==i) idx--;
else if(a[idx].sum2==a[i].sum3-2) ;
else
{
if(a[i].sum2>=a[idx].sum2)
idx --;
else idx -= 2;
}
Ans[a[i].id] = idx;
}
rep(i,1,n) cout<<Ans[i]<<' ';
cout<<endl;
//cout<<ans<<endl;
return 0;
}

Gym 102215 & 队内训练#5的更多相关文章

  1. Gym101482 NWERC 2014(队内训练第4场)

    -----------------------前面的两场感觉质量不高,就没写题解----------------------------- A .Around the Track pro:给定内多边形 ...

  2. Gym - 101480 CERC 15:部分题目题解(队内第N次训练)

    -------------------题目难度较难,但挺有营养的.慢慢补. A .ASCII Addition pro:用一定的形式表示1到9,让你计算加法. sol:模拟. solved by fz ...

  3. Gym101002 2016NAIPC(队内第7次训练)

    (由于先看的最后一题,然后又一直WA,导致这场有点爆炸,我背锅. A .Fancy Antiques 题意: 选择最多k个商店,买n个物品,每个物品分别对应两个店售卖,求最小花费是多少.n<10 ...

  4. Gym101485: NWERC 2015(队内第6次训练)

    A .Assigning Workstations 题意:给定N个人的工作时间和工作时长,我们可以假设有无数台工作机器,如果一台机器超过M时间未使用就会关闭,那么我们怎么安排机器的使用,使得需要开启机 ...

  5. OI队内测试一【数论概率期望】

    版权声明:未经本人允许,擅自转载,一旦发现将严肃处理,情节严重者,将追究法律责任! 序:代码部分待更[因为在家写博客,代码保存在机房] 测试分数:110 本应分数:160 改完分数:200 T1: 题 ...

  6. OI队内测试——石门一

    T1: 题目大意: 给你一个立方体,每个面上有些数字,给你一个数字K,你可以玩K轮游戏, 每轮你会将每个面上的数均分为4份,分给相邻的面,求K轮游戏后,上面的数字是 依次给你前.后.上.下.左.右的起 ...

  7. OI队内测试二【数论概率期望】

    版权声明:未经本人允许,擅自转载,一旦发现将严肃处理,情节严重者,将追究法律责任! 序:代码部分待更[因为在家写博客,代码保存在机房] T1: 题解:插头dp应该很好想吧,我们考虑当出现转折时我们对下 ...

  8. NOIP队内凉心互测总结(8.22update)

    8.22(结束后一天) __stdcall讲题qwq 全是CF原题 D1T1 一看像是结论题,打了下表,水过 没错就是结论题,直接暴力就好 D1T2 看起来不好做,没有AC思路 打了暴力 40分 T2 ...

  9. 【zznu-夏季队内积分赛3-J】追忆

    题目描述 “别人总说我瓜,其实我一点也不瓜,大多数时候我都机智的一批“现在是阳历2018/8/7,宝儿姐想起自己参加ACM整整1000天了.她想知道她刚入坑是什么时间.那么问题来了,请帮宝儿姐追忆一下 ...

  10. 【zznu-夏季队内积分赛3-G】2333

    题目描述 “别人总说我瓜,其实我一点也不瓜,大多数时候我都机智的一批“ 宝儿姐考察你一道很简单的题目.给你一个数字串,你能判断有多少个连续子串能整除3吗? 输入 多实例输入,以EOF结尾,每行一个数字 ...

随机推荐

  1. html中的em和rem到底该如何使用,自适应效果中如何确定文字大小/字号?

    如今手机屏幕繁多,自适应效果中如何确定文字大小/字号? em rem vm vw vh你都了解吗? 先说说em和rem em:继承父级的,假设html的font-size默认为16px,body字体大 ...

  2. kubelet 创建 Pod 前发生了什么?

    Kubelet Watch 到新增的 Pod,需要做的主要有以下几件事: 管理 Pod 状态,除了更新本地缓存,还要同步给 API server 计算节点的资源是否足够创建 Pod 创建 Cgroup ...

  3. 『Plotly实战指南』--样式定制基础篇

    在数据可视化的世界中,一个精心设计的图表不仅能准确传达信息,还能提升整体的专业性和吸引力. 而Plotly作为Python中强大的可视化库,提供了丰富的样式定制功能,帮助我们轻松实现这一目标. 本文从 ...

  4. CentOS7搭建XSS平台

    我的服务器是CentOS7.8 1.安装php 7 CentOS7的默认PHP版本是PHP5,但是如果我们要安装PHP7,不需要将现有的PHP5删除,只要将PHP升级到PHP7即可. 使用 yum p ...

  5. VC6.0工具下载安装

    公众号回复:'VC6.0'

  6. <HarmonyOS第一课13>给应用添加通知和提醒 #鸿蒙课程##鸿蒙生态#

    课程介绍 <HarmonyOS第一课:给应用添加通知和提醒>将引导开发者如何在HarmonyOS应用中实现通知功能.课程首先介绍如何为您的应用添加基础类型通知,包括普通文本.多行文本和图片 ...

  7. CentOS 7.6 安装 Mysql 5.7

    一.查看CentOS版本 Mysql的版本必须要和CentOS的版本对应!查看CentOS版本的指令如下: cat /etc/redhat-release 二.下载yum源包 wget http:// ...

  8. WindowsPE文件格式入门08.导出表

    https://bpsend.net/thread-377-1-1.html 通过cff , depends灯等软件可以看到dll,导出函数的信息,因为dll中本身就存了这些信息,存了dll中有哪些导 ...

  9. geekai开源项目二次开发 AI大模型 AI 助手全套开源解决方案

    geekai-django 基于极客学长大佬的开源项目geekai 二次开发而来. GeekAI 是基于 AI 大语言模型 API 实现的 AI 助手全套开源解决方案,自带运营管理后台,开箱即用. 介 ...

  10. odoo16跨域问题解决办法--适用app端、web端、跨系统接口

    Odoo的跨域问题: 由于浏览器的同源策略所引起的.同源策略是一种安全策略,它限制了一个源(协议.域名.端口)的文档或脚本如何与另一个源的资源进行交互. 如果两个源不同,则无法进行跨域交互.因此,如果 ...