Codeforces #200(div.2) 模拟练习赛

A题:

  • 题意:一行磁铁,同性相斥,找到这行磁铁可以分为多少块
  • 思路:边读边计算,读到和上一次不一样的就加1(第一组数据特判)
  • 手速题然而我没有把思路理清楚再写,比队友满了太多=_+。

代码:

#include <set>
#include <map>
#include <cmath>
#include <stack>
#include <queue>
#include <string>
#include <vector>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long int LL;
const int M = 100009,INF = 0x3fffffff;

int main(void) {
    //problem: cf#200, address:
    int n, y, last = -1, ans = 1;
    string x;
    cin >> n;
    while(n--) {
        cin >> x;
        if(x == "10") y = 10;
        else y = 1;
        if(last != -1 && y != last) ans++;
        last = y;
    }
    cout << ans << endl;
    return 0;
}

B题:

  • 题意:给定三个原子编号(A,B,C),每个原子一个化学价表示要与其他原子相连接的化学键个数(然而图没有给好,误导了大量时间)
  • 解法:只要知道A和B原子之间的化学键个数x,其它两条边的原子个数都可以用含有x的式子表示出来,再来检验是否满足原子价要求即可。

代码:

#include <set>
#include <map>
#include <cmath>
#include <stack>
#include <queue>
#include <string>
#include <vector>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long int LL;
const int M = 100009,INF = 0x3fffffff;

int main(void) {
    //problem:cf#200 , address:
    int a, b, c;
    cin >> a >> b >> c;
    bool ok = false;
    for(int i = 0; i <= b; i++) {
        if(b - i == c - (a - i)) {
            ok = true;
            cout << i << " " << b - i << " "<< a - i << endl;
            break;
        }
    }
    if(!ok) cout << "Impossible" << endl;
    return 0;
}

C题:

  • 题意:给定无限制个单位电阻,每一次操作可给当前电路并联或者串联一个单位电阻,求达到目标阻值(为一假分数的形式)的电阻所需要的最小操作次数。
  • 思路:开始的想法是从一个单位电阻开始,用广度优先搜索遍历出目标解的最小次数,然而这种正向求解空间是2的指数级别大小必定爆队列或者超时。然后决定由答案开始倒着推到初始状态,显然大大减少了解空间大小。有时候从目标解出发倒着推,是非常良好的思路可以大大缩减解空间大小。下午周赛A题就用了这个思想,顺利做出。
  • 注意:这个题中数据用的long long 然而我只是读入的两个数据用的long long 中间计算用到的数据却还是int 一直WA,细节。

代码:

#include <set>
#include <map>
#include <cmath>
#include <stack>
#include <queue>
#include <string>
#include <vector>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long int LL;
const int M = 100009,INF = 0x3fffffff;
LL a, b, ans;

void dfs(LL x, LL y) {
    if(y == 0) return;
    ans += x / y;
    x %= y;
    swap(x, y);
    dfs(x, y);
}

int main(void) {
    //problem: cf#200, address:
    cin >> a >> b;
    dfs(a, b);
    cout << ans << endl;
    return 0;
}

D题:

  • 题意:缠绕的绳子,问是否能够解开?
  • 思路:只要两个连着的覆盖都是同样的一根线,这两个覆盖就可以直接消除。这样很容易用一个栈一边读取一边模拟实现。

代码:


#include <set>
#include <map>
#include <cmath>
#include <stack>
#include <queue>
#include <string>
#include <vector>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long int LL;
const int M = 100009,INF = 0x3fffffff;

int main(void) {
    //problem: , address:
    char c;
    stack<int> s;
    while ((c = getchar()) != ‘\n‘) {
        int x = (c == ‘+‘ ? 1 : -1);
        if(s.empty()) {s.push(x); continue;}
        if(x == s.top()) s.pop();
        else s.push(x);
    }
    cout << (s.empty() ? "Yes" : "No") << endl;
    return 0;
}

总结:代码细节把握,思维能力训练。

时间: 2024-08-07 21:20:24

Codeforces #200(div.2) 模拟练习赛的相关文章

codeforces 614B(div.2) 模拟

模拟乘法 有毒的一题,各种细节..代码写得自己都不想看.. #include"cstdio" #include"queue" #include"cmath" #include"stack" #include"iostream" #include"algorithm" #include"cstring" #include"queue" #includ

Codeforces#200 div.2

Description Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two mag

Codeforces #259 Div.2

A. Little Pony and Crystal Mine 模拟题. 用矩阵直接构造或者直接根据关系输出 B. Little Pony and Sort by Shift 模拟题. 通过提供的操作得到的序列只能是两段递增或者整个序列递增. 那么可以求得第一段递增序列长度为0-p 如果整个序列是递增,即 p= n-1 那么操作次数就是0. 否则,假设是两段递增,把原始的序列恢复出来,设当前序列是AB,那么A就是0-p BA = (A'B')', '表示对序列进行翻转, 如果BA是有序的,那么需

Codeforces 48C The Race 模拟题

题目链接:点击打开链接 题意: 给定n个加油站,一辆车由A点跑到B点,每个100m有一个加油站,每开100m需要10升油. 在每个车站会检查一下油量,若车子若开不到下一个加油站则加x升油. 开始有x升油 下面给出加油的记录. 问下一次加油在哪一站.若答案唯一输出具体哪站. 油箱容量无限 思路: 水模拟.. #include <stdio.h> #include <string.h> #include <stdlib.h> #include <math.h>

Codeforces #258 Div.2 E Devu and Flowers

大致题意: 从n个盒子里面取出s多花,每个盒子里面的花都相同,并且每个盒子里面花的多数为f[i],求取法总数. 解题思路: 我们知道如果n个盒子里面花的数量无限,那么取法总数为:C(s+n-1, n-1) = C(s+n-1, s). 可以将问题抽象成:x1+x2+...+xn = s, 其中0<=xi <= f[i],求满足条件的解的个数. 两种方法可以解决这个问题: 方法一:这个问题的解可以等价于:mul = (1+x+x^2+...+x^f[1])*(1+x+x^2+...+x^f[2]

用div css模拟表格对角线

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>用div css模拟表格对角线</t

Codeforces #250 (Div. 2) C.The Child and Toy

之前一直想着建图...遍历 可是推例子都不正确 后来看数据好像看出了点规律 就抱着试一试的心态水了一下 就....过了..... 后来想想我的思路还是对的 先抽象当前仅仅有两个点相连 想要拆分耗费最小,肯定拆相应权值较小的 在这个基础上考虑问题就能够了 代码例如以下: #include <cstdio> #include <iostream> #include <algorithm> #define MAXN 10010 #define ll long long usi

【转载】用div+css模拟表格对角线

本文引用蓝色理想论坛. 首先声明: 这只是探讨一种CSS模拟表格对角线的用法,实际在工作中可能觉得这样做有点小题大作,这不是本主题讨论的重点.如果对此深以为然的朋友,请一笑过之... 有时在插入文档时,要用到表格对角线,常见的作法是用图片的方式来处理,还有就是用vml来画对角线,能不能用html+css方式来实现呢?答案是肯定的,下面我们来摸拟一个表格对角线. 原理: 用边框线来摸拟斜线,我们知道,如果将一个DIV的边框线设置得足够宽并定义了不同的颜色时,其相邻的两条边框线交界处就是斜线.知道了

Codeforces #256 Div.2

B. Suffix Structure 1. 先判断s去掉一些元素是否能构成t,如果可以就是automaton 判断的方法也很简单,two pointer,相同元素同时++,不相同s的指针++,如果t能全找到,那么s能够去掉元素构成t. bool f(string s, string t) { int i = 0, j = 0; while (i < s.size() && j < t.size()) { if (s[i] == t[j]) { i++; j++; } else