Codeforces Div3 #501 A-E(2) F以后补
感觉自己有点强迫症 不都写出来就找理由不写题解
http://codeforces.com/contest/1015 题目链接
A. Points in Segments
题目意思 n个线段 去覆盖1-m 中的点 问你没有覆盖的点的个数和位置
这个数据很小,可以直接暴力查找
思考:如果n<1e6, m<=1e8 呢?
#include<bits/stdc++.h>
#define int long long
#define MAX(a,b,c) max(a,max(b,c))
#define MIN(a,b,c) min(a,min(b,c))
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef long long LL;
typedef unsigned long long ull;
typedef unsigned long long uLL;
using namespace std;
const int maxn=1e5+;
const int INF=0x3f3f3f3f;
map<int,int> mp;
int32_t main()
{
int n,m;
cin>>n>>m;
for(int i=;i<=n;i++)
{
int a,b; cin>>a>>b;
for(int j=a;j<=b;j++)
mp[j]=;
}
int t=;
for(int i=;i<=m;i++)
{
if(mp[i]==)
{
t++;
}
}cout<<t<<endl;
for(int i=;i<=m;i++)
{
if(mp[i]==)
{
cout<<i<<" ";
}
}
}
A.cpp
如果 m<=1e8的 话,可以标记 线段的起点 重点后一位 左右搜一遍
如1-5 a[1]=1; a[6]=-1;
B. Obtaining the String
一个n,两个字符串(ss,tt),左右移动前一个字符串 使两个字符串相等 求最小移动次数;
对比 ss ,tt 当ss[i] !=tt[i]; 在ss[i]后面找和tt[i]一样的, 移动到ss[i];没有就输出-1;
#include<bits/stdc++.h>
#define int long long
#define MAX(a,b,c) max(a,max(b,c))
#define MIN(a,b,c) min(a,min(b,c))
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef long long LL;
typedef unsigned long long ull;
typedef unsigned long long uLL;
using namespace std;
const int maxn=1e5+;
const int INF=0x3f3f3f3f;
map<int,int> mp;
vector<int> pp;
int32_t main()
{
int n; cin>>n;
string ss,tt; cin>>ss; cin>>tt;
//if(ss==tt) { cout<<-1<<endl; return 0;}
int j=;
for(int i=;i<n;i++)
{
if(ss[j]==tt[i])
{
j++; continue;
}
int t=;
for(int k=j+;k<n;k++)
{ if(ss[k]==tt[i])
{
for(int x=k-;x>=j;x--)
{
swap(ss[x],ss[x+]);
t=;
pp.push_back(x+);
}
if(t==) { j++;break;}
}
}
if(t==) { cout<<-<<endl; return ;}
}
cout<<pp.size()<<endl;
for(int i=;i<pp.size();i++)
{
cout<<pp[i]<<" ";
}
}
B.cpp
C. Songs Compression
n 组数据 一开始的歌曲数据大小 压缩后的数据大小, 要是数据小于等于m;
直接计算一开始的大小,每次减去 差值最大的;看多少次后数据小于等于m; 压缩不到m就输出-1;
#include<bits/stdc++.h>
#define int long long
#define MAX(a,b,c) max(a,max(b,c))
#define MIN(a,b,c) min(a,min(b,c))
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef long long LL;
typedef unsigned long long ull;
typedef unsigned long long uLL;
using namespace std;
const int maxn=1e5+;
const int INF=0x3f3f3f3f;
int a[maxn];
int b[maxn];
int d[maxn];
int32_t main()
{
int n,m; cin>>n>>m; int ans1=; int ans2=;
for(int i=;i<=n;i++)
{
cin>>a[i]>>b[i];
d[i]=a[i]-b[i];
ans1+=a[i];
ans2+=b[i];
}
if(ans2>m) { cout<<-<<endl;return ;}
//if(ans1<=m) { cout<<0<<endl;return 0;}
sort(d+,d++n); int t=;
for(int i=n;i>=;i--)
{
if(ans1<=m) break;
ans1=ans1-d[i];
t++;
}
cout<<t<<endl;
}
C.cpp
D. Walking Between Houses
在1-n 中走 k次(随你走到哪,不能不走) 使走的路程为 s;
在保证每次都至少走一步的情况下 先走最大的 1 - n- 1 - n -1 -n....;
最后再每次走一步;
10 9 45 来说 每次走的距离为 9 9 9 9 5 1 1 1 1;
#include<bits/stdc++.h>
#define int long long
#define MAX(a,b,c) max(a,max(b,c))
#define MIN(a,b,c) min(a,min(b,c))
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef long long LL;
typedef unsigned long long ull;
typedef unsigned long long uLL;
using namespace std;
const int maxn=1e5+;
const int INF=0x3f3f3f3f;
int32_t main()
{
int n,k,s; cin>>n>>k>>s;
if(s>(n-)*k||s<k) { cout<<"NO"<<endl; return ;}
cout<<"YES"<<endl;
int t=;
while(s)
{
if(s-n+>=k-)
{
if(t%==) cout<<n<<" ";
else cout<<<<" ";
t++;
k--;
s=s-(n-); //cout<<s<<endl;
}
else
{
int d=s-(k-);// cout<<d<<endl;
int pos=;
if(t%==) { cout<<+d<<" "; pos=+d; }
else { cout<<n-d<<" "; pos=n-d;}
t++;
k--;
int x=;
while(k)
{
if(x%==)
{
if(pos->=) cout<<pos-<<" ";
else cout<<pos+<<" ";
}
else cout<<pos<<" ";
k--;
x++;
}
break;
}
}
}
D.cpp
E1. Stars Drawing (Easy Edition)
可以直接暴力搜 找到一个点 直接往上下左右搜 看照射的距离 大于1就全部标记
#include<bits/stdc++.h>
#define int long long
#define MAX(a,b,c) max(a,max(b,c))
#define MIN(a,b,c) min(a,min(b,c))
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef long long LL;
typedef unsigned long long ull;
typedef unsigned long long uLL;
using namespace std;
pair<int,int> pos[]={ {,},{,-},{,},{-,} };
bool tf[][];
char a[][];
int x2[];
int x1[];
int x3[];
int32_t main()
{
int n,m; cin>>n>>m; getchar();
for(int i=;i<n;i++)
gets(a[i]);
int t=;
for(int i=;i<n;i++)
{
for(int j=;j<m;j++)
{
if(a[i][j]=='*')
{
//cout<<i<<" "<<j<<endl;
int z=;
while()
{
int x=;
for(int k=;k<;k++)
{
int x1=i+z*pos[k].first;
int y1=j+z*pos[k].second;
if(x1<||x1>=n||y1<||y1>=m)
{
continue;
}
if(a[x1][y1]=='*')
{
x++;
} }
//cout<<x<<endl;
if(x==)
{
tf[i][j]=;
for(int k=;k<;k++)
{
int x1=i+z*pos[k].first;
int y1=j+z*pos[k].second;
if(x1<||x1>=n||y1<||y1>=m)
{
continue;
}
if(a[x1][y1]=='*')
{
tf[x1][y1]=;
} }
}
else break;
z++;
}
if(z==) continue;
else
{
x1[t]=i;
x2[t]=j;
x3[t]=z-; t++;
}
}
}
} // cout<<t<<endl;
int k1=;
int k2=;
for(int i=;i<n;i++)
{
for(int j=;j<m;j++)
{
if(a[i][j]=='*') k1++;
if(tf[i][j]==) k2++;
}
}
if(k1!=k2) cout<<-<<endl;
else
{
cout<<t<<endl;
for(int i=;i<t;i++)
{
cout<<x1[i]+<<" "<<x2[i]+<<" "<<x3[i]<<endl;
}
} //cout<<k1<<" "<<k2<<endl;
}
E1.cpp
E2. Stars Drawing (Hard Edition)
先预处理 每个点 上下左右 可以照射的距离 再标记
预处理有些技巧 ,不能暴力搜 要找相邻两个点的关系
由于预处理 和 标记 分开 不会超时;
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e3+;
int l[maxn][maxn];
int r[maxn][maxn];
int u[maxn][maxn];
int d[maxn][maxn];
int ans1[maxn*maxn];
int ans2[maxn*maxn];
int ans3[maxn*maxn];
char a[maxn][maxn];
bool f[maxn][maxn];
int main()
{
int n,m;
cin >> n >> m;
int i,j,s,y;
for (i = ; i <= n; i++)
for (j = ; j <= m; j++) cin >> a[i][j];
for (i = ; i <= n; i++) for (j = ; j <= m; j++)
if (a[i][j] == '*') l[i][j] = l[i][j-] + ; else l[i][j] = ; for (i = ; i <= n; i++) for (j = m; j >= ; j--)
if (a[i][j] == '*') r[i][j] = r[i][j+] + ; else r[i][j] = ; for (j = ; j <= m; j++) for (i = ; i <= n; i++)
if (a[i][j] == '*') u[i][j] = u[i-][j] + ; else u[i][j] = ; for (j = m; j >= ; j--) for (i = n; i >= ; i--)
if (a[i][j] == '*') d[i][j] = d[i+][j] + ; else d[i][j] = ; int t=;
for (i = ; i <= n; i++)
for (j = ; j <= m; j++) if (a[i][j] == '*') {
s = min(min(r[i][j+],l[i][j-]),min(u[i-][j],d[i+][j]));
if (s > ) {
ans1[t]=i; ans2[t]=j; ans3[t]=s; t++; for (y = j-s; y <= j+s; y++) f[i][y] = ;
for (y = i-s; y <= i+s; y++) f[y][j] = ;
}
}
for (i = ; i <= n; i++) for (j = ; j <= m; j++)
if (a[i][j] == '*' && f[i][j] == ) {
cout << - << endl;
return ;
}
cout<<t-<<endl;
for(int i=;i<=t-;i++)
cout<<ans1[i]<<" "<<ans2[i]<<" "<<ans3[i]<<endl;
}
E2.cpp
Codeforces Div3 #501 A-E(2) F以后补的更多相关文章
- Codeforces Round #501 (Div. 3) F. Bracket Substring
题目链接 Codeforces Round #501 (Div. 3) F. Bracket Substring 题解 官方题解 http://codeforces.com/blog/entry/60 ...
- Codeforces Round #598 (Div. 3) A,B,C,D{E,F待补}
A. Payment Without Change #include<bits/stdc++.h> using namespace std; #define int long long ...
- Codeforces Round #535 (Div. 3) [codeforces div3 难度测评]
hhhh感觉我真的太久没有接触过OI了 大约是前天听到JK他们约着一起刷codeforces,假期里觉得有些颓废的我忽然也心血来潮来看看题目 今天看codeforces才知道居然有div3了,感觉应该 ...
- Codeforces Round #541 (Div. 2) (A~F)
目录 Codeforces 1131 A.Sea Battle B.Draw! C.Birthday D.Gourmet choice(拓扑排序) E.String Multiplication(思路 ...
- Codeforces Round #519 by Botan Investments F. Make It One
https://codeforces.com/contest/1043/problem/F 题意 给你n个数,求一个最小集合,这个集合里面数的最大公因数等于1 1<=n<=3e5 1< ...
- Codeforces Round #532 (Div. 2):F. Ivan and Burgers(贪心+异或基)
F. Ivan and Burgers 题目链接:https://codeforces.com/contest/1100/problem/F 题意: 给出n个数,然后有多个询问,每次回答询问所给出的区 ...
- Codeforces Round #590 (Div. 3)(e、f待补
https://codeforces.com/contest/1234/problem/A A. Equalize Prices Again #include<bits/stdc++.h> ...
- Codeforces Round #600 (Div. 2)E F
题:https://codeforces.com/contest/1253/problem/E 题意:给定n个信号源,俩个参数x和s,x代表这个信号源的位置,s代表这个信号源的波及长度,即这个信号源可 ...
- Codeforces Round #346 (Div. 2) E F
因为很久没有个人认真做题了 昨天晚上开了场虚拟cf来锻炼个人手速 选的是第一次做cf的场 那时候7出3还被hack...之后也没补题 这次做的时候顺便回忆了一下以前比赛的时候是怎么想的 发现经验还是很 ...
随机推荐
- java倒计时使用ScheduledExecutor实现,使用两个线程,以秒为单位
public class Countdown2 { private volatile int lin; private int curSec; public Countdown2(int lin) t ...
- django+xadmin+echarts实现数据可视化
使用xadmin后功能比较强大,在后台展示统计图表,这个需求真的有点烫手,最终实现效果如下图: xadmin后台与echarts完全融合遇到以下问题: 1.没有现成的数据model 2.获得指定时间段 ...
- 通过滑动条控制Cube旋转
private float speed = 10; private float speedValue; private GameObject slider; private GameObject cu ...
- Windows系统上设置 Git Bash 的 Font 及 Locale
在windows 上使用 Git Bash 可以获得 unix 命令 操作体验. 但是初始的Git Bash的字体及语系都很不方便,需要自己设置. 在Git Bash的命令窗体上边框点击鼠标右键可以进 ...
- Java Web相关概念调查
- Java语法基础学习DaySeven
---恢复内容开始--- 一.包装类——Wrapper 1.定义:针对八种基本数据类型定义相应的引用类型——包装类(封装类) boolean——Boolean byte——Byte ...
- L305 发邮件15分钟
发个邮件-不用那么纠结-把事情讲清楚就好-限制在15分钟写完-长的邮件25分钟-难点是讲清楚细节-比如软件调试bug-DFM-这里有些专业词汇 发现问题:发给客户的There are some qua ...
- centos /data目录扩容
/data盘被日志撑死了,必须扩容 有一块现成的100G的/dev/sdb盘,但是mount到了/data/test目录下,而且还有应用程序在上面进行读写操作 1.先查看哪些应用程序 在占用磁盘 #f ...
- react 学习笔记 npm 命令
第一步: cnpm install --save react react-dom babelify babel-preset-react 第二步: 安装es2015 cnpm install babe ...
- IE6以下版本对元素width和height的处理与CSS标准的兼容性问题
1.CSS使用width和height定义元素框的内容,Windows平台的IE6以下版本浏览器并未按照标准处理而是使用width和height来定义可见元素框的尺寸,IE/win使用width来描述 ...