CF 725C 模拟 725D

CodeForces 725C

题意:长27的字符串,26个英文字母至少出现了一次。这个字符串是由两行13列的字符相邻行走得来,求这个两行13列的字符。

题解:思路很好想,找其中两个一样的字符,间距d,平分到两行。  注:以后写草稿要写清楚点。。被自己坑死了。。

#include<bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:102400000,102400000")
#define FF(i,a,b) for (int i=a;i<=b;i++)
#define F(i,b,a)  for (int i=b;i>=a;i--)
#define mes(a,b)  memset(a,b,sizeof(a))
#define INF 0x3f3f3f3f
typedef long long ll;
const int N = 2e5+10;

int main()
{
    string s;
    char s1[50], s2[50];
    cin>>s;
    int a, b;
    FF(i,0,26) FF(j,0,i-1)
        if(s[i]==s[j])  a=j, b=i;
    int i, j, x=b-a, y=(x+1)/2;
    if(x==1) { puts("Impossible"); return 0; }
    for(i=12-y+1,j=a; i<=12; i++,j++) s1[i]=s[j];
    for(i=12; j<b; i--,j++) s2[i]=s[j];
    for(j=b+1; i>=0&&j<=26; i--,j++) s2[i]=s[j];
    if(j==27) {
        for(j=0; i>=0&&j<a; i--,j++) s2[i]=s[j];
        for(i=0; j<a; i++,j++) s1[i]=s[j];
    }
    else {
        for(i=0; j<=26; i++,j++) s1[i]=s[j];
        for(j=0; j<a; i++,j++) s1[i]=s[j];
    }
    s1[13]=s2[13]=‘\0‘;
    cout<<s1<<endl<<s2<<endl;

    return 0;
}

CodeForces 725D

题意:n个人,每人有ti个气球,wi重量。当ti>wi时,他飞走。按最后留下的人的气球数量排名,第一个人可以把气球给其它人,求第一个人最后尽可能高的排名。

题解:一开始总想怎么排序,应该把握好关键点,就是每次找到可以放飞且给出气球数量最少的人即可。所以用个优先队列就好了。把所有比第一个人气球多的人加入队列,队列内部按要增加的气球数排序。每次把队列中首个人放飞,这时候要继续往队列中加人,同时比较一下答案,直到不能放飞为止。

#include<bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:102400000,102400000")
#define FF(i,a,b) for (int i=a;i<=b;i++)
#define F(i,b,a)  for (int i=b;i>=a;i--)
#define mes(a,b)  memset(a,b,sizeof(a))
#define INF 0x3f3f3f3f
typedef long long ll;
const int N = 3e5+10;

struct P{
    ll ti, wi, ci;
    friend bool operator < (const P & a, const P &b) {
        return a.ci>b.ci;
    }
}p[N];
int n, ans;
ll t1, w1, s[N];
priority_queue<P >A;
bool cmp(P a, P b)
{
    return a.ti<b.ti;
}
int main()
{
    scanf("%d", &n);
    scanf("%lld%lld", &t1, &w1);
    FF(i,2,n) {
        scanf("%lld%lld", &p[i].ti, &p[i].wi);
        p[i].ci=p[i].wi-p[i].ti+1;
        if(p[i].ti>t1) A.push(p[i]);
    }
    sort(p+2, p+1+n, cmp);
    for(int i=2; i<=n; i++)  s[i]=p[i].ti;
    ans=A.size()+1;
    ll l=upper_bound(s+2, s+1+n, t1)-s, r;
    while(true) {
        if(A.empty()) { printf("%d\n", ans); return 0; }
        if(A.top().ci<=t1) {
            P st=A.top();  A.pop();
            r=l, l=upper_bound(s+2, s+1+n, t1-st.ci)-s;
            for(int i=r-1; i>=l; i--) {
                A.push(p[i]);
            }
            int m=A.size()+1;
            t1-=st.ci;
            if(ans>A.size()+1) ans=A.size()+1;
        }
        if(A.top().ci>t1) { printf("%d\n", ans); return 0; }
    }

    return 0;
}

时间: 2024-10-08 08:15:59

CF 725C 模拟 725D的相关文章

CF 729D 模拟,思维

CF 729 D. Sea Battle 题意:n个单位长的海域,有a只船,船长为b.已经开了k枪没有射中,求最少再开几枪可射中一只船. 题解:转变一下思维,求开了k枪后可放入多少只船.要求再开几枪可射中一只船,只要 -a+1即可. #include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") #define FF(i,a,b) for (

CF 821C 模拟

x入栈的同时 也加入集合b, 当a.top()!=num  直接reorder复杂度为n^2logn  改为清空栈,当栈为空时 表示栈已经有序,删除元素直接从集合中删除. #include <bits/stdc++.h> using namespace std; typedef long long ll; const int N=2e6+20; int n,p[N]; char s[20]; stack<int> a; set<int> b; int main() {

CF 378(2) C D 模拟

CF 378(2)   好坑,有时间再做一遍 CodeForces 733C 题意:n只怪物,每只重ai,一开始有给定序列a[].问最后是否能变到x只特定序列b[],变化只能是相邻的大吃小. 题解:坑死人的题,,但不要怕去写这种题,在草稿纸上写好思路,一定要动手写.  思路:先把a[]根据b[]进行分段,再对每一段进行分析.细节太多,不自己动手写一遍根本体会不到.. #include<bits/stdc++.h> using namespace std; #pragma comment(lin

CF #392(2) C 暴力模拟

CF #392(2)  C. Unfair Poll 题意:n行m列人,老师点k次名.点名次序,每一行都是从1到m,但行是按1,2....(n-1),n,(n-1),(n-2)...1,2,3....(n-1),n.....求点完k次名后被点的最多的次数和最少的次数,以及给定的(x,y)被点次数. 总结:有点麻烦,但还是很好找规律,只是fst了,有时间再写一遍...还是太菜了,连着三场CF都是fst #include<bits/stdc++.h> using namespace std; #p

CF 395(2) D.矩形上色,模拟

CF 395(2)  D. Timofey and rectangles 题意:二维平面上n个矩形上色,矩形边长都是奇数,且不会重合.用4种颜色上色,要使相邻的矩形是不同的颜色,求每个矩形的颜色. 题解:因为都是矩形,3种颜色就可以做到相邻矩形是不同颜色.这里因为矩形边长都是奇数,稍微脑补一下,可以将矩形以左下角点分为4种,奇数行奇数列,奇数行偶数列,偶数行奇数列,偶数行偶数列. #include<bits/stdc++.h> using namespace std; #pragma comm

【打CF,学算法——三星级】Codeforces 704A Thor (模拟)

[CF简介] 题目链接:CF 704A 题面: A. Thor time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Thor is getting used to the Earth. As a gift Loki gave him a smartphone. There are n applications on this ph

CF 2A Winner(STL+模拟)

题目链接:http://codeforces.com/contest/2/problem/A 题目: The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points,

CF 815 A. Karen and Game(暴力,模拟)

题目链接:http://codeforces.com/problemset/problem/815/A 题目: On the way to school, Karen became fixated on the puzzle game on her phone! The game is played as follows. In each level, you have a grid with n rows and m columns. Each cell originally contains

CF 888C K-Dominant Character(模拟)

题目链接:http://codeforces.com/problemset/problem/888/C 题目: You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimu