codeforces 555

最近爱做codeforces。。。。。像比赛题而且有样例,,,嘻嘻

A:因为题意卡了我两回(开始以为必须是10才消掉。。。后来又以为只算1的个数),,其实没啥说的

#include <iostream>

#include<bits/stdc++.h>

using namespace std;

int main()

{

int m;

scanf("%d",&m);

char a[200001];

scanf("%s",a);

int sum=0;

int sum2=0;

int i;

for(i=0;i<strlen(a);i++)

{

if(a[i]==‘1‘) sum++;

else sum2++;

}

printf("%d\n",abs(sum-sum2));

return 0;

}

B:其实应该是有规律的(比如m是偶数奇数位和偶数位一样啊神马的。。。。不过直接模拟了。。。)

#include <iostream>

#include<bits/stdc++.h>

using namespace std;

int main()

{

int m;

scanf("%d",&m);

int a[1001];

int i;

for(i=0;i<m;i++)

{

scanf("%d",&a[i]);

}

int n=m-a[0];

for(i=1;i<m;i++)

{

if(i%2==1)

{

if(a[i]-n!=i&&((m-n+a[i])!=i))

{

printf("No\n");

//printf("%d**\n",i);

return 0;

}

}

else

{

if(a[i]+n!=i&&(n-m+a[i]!=i))

{

printf("No\n");

//printf("%d**\n",i);

return 0;

}

}

}

printf("Yes\n");

return 0;

}

C:只可以留从1开始的链剩下的全拆掉= = ,,,,开始以为只要是连续的都不拆呢,,,,,哎(有点改的乱了,,本来以为要判断有多少连续的链呢)

#include <iostream>

#include<bits/stdc++.h>

using namespace std;

int main()

{

int geshu,lianshu;

scanf("%d%d",&geshu,&lianshu);

int a;

int w,q;

int i,j;

int t=0,bufen=0;

for(i=0;i<lianshu;i++)

{

scanf("%d",&a);

scanf("%d",&w);

if(w==1)

{

for(j=1;j<a;j++)

{

scanf("%d",&q);

if(q==w+1) w++;

else

{

bufen++;

t++;

}

}

}

else

{for(j=1;j<a;j++)

{

scanf("%d",&q);

t++; bufen++;

}}

}

printf("%d\n",bufen+lianshu+t-1);

return 0;

}

D:好难哦。。。。。。。用的就是贪心了,,,,,,只是这题用到了类和容器,对我来说有点难度(至少要用容器不然查找到了删除太费劲了。。)

其实不太熟,,勉强做的

#include <iostream>

#include<bits/stdc++.h>

using namespace std;

pair<int64_t,int64_t>pa[200000];

set<pair<int64_t, int> >X;

pair<int64_t,pair<int64_t,int> >diff[200000];

int ans[200000];

bool cmp(pair<int64_t,pair<int64_t,int> >p1 , pair<int64_t,pair<int64_t,int> >p2)

{

return p1.first > p2.first || (p1.first == p2.first && p1.second.first > p2.second.first);

}

int main()

{

ios_base::sync_with_stdio(false); //这个语句是让cin,cout更快的

cin.tie(NULL), cout.tie(NULL);    //加快执行效率。。。。

int n,m; cin >> n >> m;

for(int i = 0; i < n; i ++)

{

int64_t a,b;

cin >> a >> b;

pa[i] = make_pair(a,b);  //make_pair 将a,b构造成pair类型赋值pa中

}

sort(pa,pa+n);               //直接排序

for(int i = 0; i < m; i ++){

int64_t a;

cin >> a;

X.insert(make_pair(a,i+1));      //将桥的长度和序号做成pair放入X中

}

for(int i = 0; i < n-1; i ++){

diff[i] = make_pair(pa[i+1].first-pa[i].second ,make_pair(pa[i+1].second - pa[i].first,i));  //两个岛的最大与最小距离,,还有对应的i

}

sort(diff,diff+n-1,cmp);

set<pair<int64_t,int> > :: iterator it;  //迭代器,用于遍历(类似指针吧~)

for(int i = 0; i < n-1; i ++)

{

int64_t d = diff[i].first;

int64_t s = diff[i].second.first;  //最大的值

it = X.lower_bound(make_pair(s+1,0));  //二分查找

if(it == X.begin())  //走到了尽头

{

cout << "No\n";

return 0;

}

it--;

if(it!=X.end())

{

if((*it).first < d)   //没走到头但是已经不行了

{

cout << "No\n";

return 0;

}

}

else            //走到了尽头

{

cout << "No\n";

return 0;

}

ans[diff[i].second.second] = (*it).second;

X.erase(it);

}

cout << "Yes\n";

for(int i = 0; i < n-1; i ++)

cout << ans[i] << ‘ ‘;

}

路漫漫其修远兮。





版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-08-28 11:53:53

codeforces 555的相关文章

codeforces 555 C Case of Chocolate

一开始题目读错了,还以为可以从任意点为起点向上向左吃. 其实是只能从右边的边界为起点吃. 于是很明显,每一个横坐标最多只能出现一次,否则肯定是当前这个起点的巧克力已经被啃食了. 想到这里就更明显了,对于(xi,n+1-xi),若是向上吃,能够影响它的操作(xj,n+1-xj)肯定满足xj>xi,然后又明显一点,最小的xj肯定能影响到它. 我们来考虑操作(xj,n+1-xj), 若它是往左吃,很显然此时操作(xi,n+1-xi)能吃到被(xj,n+1-xj)吃掉的地方为止. 若它是往上吃呢?很显然

Codeforces Round # 555 (Div. 3) C2. Increasing subsequence (complicated version) (贪心)

题目链接:http://codeforces.com/contest/1157/problem/C2 当左右两边数字相同时,需要判断一下取哪边能得到更长的递增序列 #include <iostream> #include <cstring> #include <algorithm> #include <cmath> #include <cstdio> #include <queue> #include <climits>

Codeforces Round #555 div3 C2

题目大意 给出一个序列,可以从左或从右侧取数,要求取出的序列严格上升 思路 贪心取左右最小的,如果相等则之后只能从一侧取,直接选能取最长的一侧 Code: #include<bits/stdc++.h> #define ll long long #define inf 0x3f3f3f3f using namespace std; int ma[10]; int n; int a[(int)(2*1e5)+10]; int main(){ scanf("%d",&n

Codeforces Round #555 (Div. 3)[1157]题解

不得不说这场div3是真的出的好,算得上是从我开始打开始最有趣的一场div3.因为自己的号全都蓝了,然后就把不经常打比赛的dreagonm的号借来打这场,然后...比赛结束rank11(帮dreagonm上蓝果然没有食言qwq). (震惊...HA省A队CF青名...) CF1157A Reachable Numbers 水题,分析一下不难发现不超过\(10\)次就会少一位,然后\(10^9\)范围内的数可以到达的数个数显然不多,不妨大力模拟,然后把出现的数扔进set,最后输出set.size(

Codeforces Round #555 Div. 3

题目链接:戳我 完了,最菜就是我了.div.3都写不动QAQ A 按照题意模拟即可,注意判重 #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> #include<vector> #include<map> #define MAXN 100010 using namespace std; int

Codeforces Round #555 (Div. 3) A B C1(很水的题目)

A. Reachable Numbers 题意:设f(x)为 x+1 这个数去掉后缀0的数,现在给出n,问经过无数次这种变换后,最多能得到多少个不同的数. 代码 #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #include<queue> #include<stack> #include<set> #include<

E Minimum Array ( Codeforces Round #555 (Div. 3) )

You are given two arrays aa and bb, both of length nn. All elements of both arrays are from 00 to n−1n−1. You can reorder elements of the array bb (if you want, you may leave the order of elements as it is). After that, let array cc be the array of l

codeforces 555B Case of Fugitive

题目连接: http://codeforces.com/problemset/problem/555/B 题目大意: 有n个岛屿(岛屿在一列上,可以看做是线性的,用来描述岛屿位置的是起点与终点),m个桥,给出每个岛屿的位置和桥的长度,问是否可以把n个岛屿连起来? 解题思路: 排序+贪心,对于n个岛屿,相邻的两个之间起点和端点可以转化为n-1个连接桥的长度区间,把区间升序排列. 对于m个桥升序排列,对于每一个桥枚举每个可以合法覆盖的区间,选取最优的,选取的时候满足L<bridge_length<

Codeforces Round #292 (Div. 2 Div. 1)

比赛链接:http://codeforces.com/contest/515  http://codeforces.com/contest/516 A. Drazil and Date time limit per test 1 second memory limit per test 256 megabytes Someday, Drazil wanted to go on date with Varda. Drazil and Varda live on Cartesian plane. D