http://codeforces.com/contest/282

A:水,找到中间的算符,处理就行。

B:

话说比赛的时候竟然没有想法,无语了。给出n对数,ai,bi ;    ai + bi = 1000 ,求满足sa表示美对数取a的和与sb每对数取b的和之间的差值的绝对值小于等于500。对于每一对数要么取a,要么取b. 取A同A表示取b用G表示,输出最后的结果如果不存在输出-1

我们只要 贪心的选择,如果选A满足就给sa,如果选b满足就给sb,这样走下来就行。

View Code

By E_star, contest: Codeforces Round #173 (Div. 2), problem: (B) Painting Eggs, Accepted, #//#pragma comment(linker,"/STACK:327680000,327680000")
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <algorithm>
#include <string>
#include <set>
#include <functional>
#include <numeric>
#include <sstream>
#include <stack>
#include <map>
#include <queue>#define CL(arr, val)    memset(arr, val, sizeof(arr))#define lc l,m,rt<<1
#define rc m + 1,r,rt<<1|1
#define pi acos(-1.0)
#define ll __int64
#define L(x)    (x) << 1
#define R(x)    (x) << 1 | 1
#define MID(l, r)   (l + r) >> 1
#define Min(x, y)   (x) < (y) ? (x) : (y)
#define Max(x, y)   (x) < (y) ? (y) : (x)
#define E(x)        (1 << (x))
#define iabs(x)     (x) < 0 ? -(x) : (x)
#define OUT(x)  printf("%I64d\n", x)
#define lowbit(x)   (x)&(-x)
#define Read()  freopen("din.txt", "r", stdin)
#define Write() freopen("dout.txt", "w", stdout);
#define inf 0x7f7f7f7f#define M 107
#define N 1000007
using namespace std;int a[N],b[N],ans[N];int Abs(int x)
{if (x >= 0) return x;else return (-x);
}
int main()
{int n;int i,j;while (~scanf("%d",&n)){for (i = 0; i < n; ++i){scanf("%d%d",&a[i],&b[i]);}int sa = 0;int sb = 0;for (i = 0; i < n; ++i){
//            printf("%d %d\n",sa + a[i] - sb,sa - (sb + b[i]));if (Abs(sa + a[i] - sb) <= 500){sa += a[i];ans[i] = 0;}else if (Abs(sa - (sb + b[i])) <= 500){sb += b[i];ans[i] = 1;}else{break;}}if (i < n){printf("-1\n");}else{for (i = 0; i < n; ++i){if (ans[i] == 0) printf("A");else printf("G");}printf("\n");}}return 0;
}

C:

xor   or

1 1   0     1

0 1   1     1

1 0   1     1

0 0   0     0

观察可知, 1 1 组和会减少一个1, 1 0 或 01 组和会增加一个1.我们只需要判断1的个数即可,只要a1 > b1 我们就可以通过 11来减少1 达到b状态,  a1 == b1 肯定就想相等了(1与0的个数两个状态时相等的) a1 < b1 我们就可以通过01来增加1达到b状态了。(我们需要注意的是,a1 > b1时,注意b1是否为0 ,因为a1不会变为0个1的状态,同理a1 < b1一样注意0的状态)

View Code

#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <algorithm>
#include <string>
#include <set>
#include <functional>
#include <numeric>
#include <sstream>
#include <stack>
#include <map>
#include <queue>#define CL(arr, val)    memset(arr, val, sizeof(arr))#define lc l,m,rt<<1
#define rc m + 1,r,rt<<1|1
#define pi acos(-1.0)
#define ll __int64
#define L(x)    (x) << 1
#define R(x)    (x) << 1 | 1
#define MID(l, r)   (l + r) >> 1
#define Min(x, y)   (x) < (y) ? (x) : (y)
#define Max(x, y)   (x) < (y) ? (y) : (x)
#define E(x)        (1 << (x))
#define iabs(x)     (x) < 0 ? -(x) : (x)
#define OUT(x)  printf("%I64d\n", x)
#define lowbit(x)   (x)&(-x)
#define Read()  freopen("din.txt", "r", stdin)
#define Write() freopen("dout.txt", "w", stdout);
#define inf 0x7f7f7f7f#define M 107
#define N 1000007
using namespace std;char a[N];
char b[N];int main()
{int i,j;int a1,a0,b1,b0;a1 = a0 = b1 = b0 = 0;scanf("%s%s",a,b);int La = strlen(a);int Lb = strlen(b);if (La != Lb){printf("NO\n");}else{for (i = 0; i < La; ++i){if (a[i] == '0') a0++;else a1++;if (b[i] == '0') b0++;else b1++;}if (a1 == b1) printf("YES\n");else if (a1 > b1){if (b1 == 0) printf("NO\n");else printf("YES\n");}else if (a1 < b1){if (a1 == 0) printf("NO\n");else printf("YES\n");}}return 0;
}

D:

当n  == 1时 是巴什博奕

当n == 2时是 威佐夫博奕

当n == 3时是尼姆博弈(这里需要证明一下,对于3堆,同时取每一堆相同的个数,不会影响)

View Code

#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <algorithm>
#include <string>
#include <set>
#include <functional>
#include <numeric>
#include <sstream>
#include <stack>
#include <map>
#include <queue>#define CL(arr, val)    memset(arr, val, sizeof(arr))#define lc l,m,rt<<1
#define rc m + 1,r,rt<<1|1
#define pi acos(-1.0)
#define ll __int64
#define L(x)    (x) << 1
#define R(x)    (x) << 1 | 1
#define MID(l, r)   (l + r) >> 1
#define Min(x, y)   (x) < (y) ? (x) : (y)
#define Max(x, y)   (x) < (y) ? (y) : (x)
#define E(x)        (1 << (x))
#define iabs(x)     (x) < 0 ? -(x) : (x)
#define OUT(x)  printf("%I64d\n", x)
#define lowbit(x)   (x)&(-x)
#define Read()  freopen("din.txt", "r", stdin)
#define Write() freopen("dout.txt", "w", stdout);#define M 150
#define N 4100007
using namespace std;int a[4];int solve(int a,int b)
{if (a > b) swap(a,b);int k = b - a;int ak = k*(1 + sqrt(5))/2;if (ak == a) return 0;else return 1;
}
int main()
{int n,i;while (~scanf("%d",&n)){int flag = 0;for (i = 0; i < n; ++i) scanf("%d",&a[i]);if (n == 1) flag = a[0];else if (n == 2) flag = solve(a[0],a[1]);else flag = a[0]^a[1]^a[2];if (flag != 0) printf("BitLGM\n");else printf("BitAryo\n");}return 0;
}

E:

给出n个数求前P个一会的结果与后q个抑或的结果之间抑或的最大结果。

思路:Trie树 + 贪心

首先我们将所前i个数抑或的结果(二进制)存放到Trie树种,然后枚举后缀,在Trie树上贪心的选择与之抑或最大的值。这里最关键的是题目要求不能存在前缀与后缀相交,但是我们贪心的选择前缀时,确实没有排除相交的可能,但是我们想一想的话,如果存在相交,他们两个在疑惑不久取消了吗,之间相当于没有相交。经典的题目...

View Code

#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <algorithm>
#include <string>
#include <set>
#include <functional>
#include <numeric>
#include <sstream>
#include <stack>
#include <map>
#include <queue>#define CL(arr, val)    memset(arr, val, sizeof(arr))#define lc l,m,rt<<1
#define rc m + 1,r,rt<<1|1
#define pi acos(-1.0)
#define ll __int64
#define L(x)    (x) << 1
#define R(x)    (x) << 1 | 1
#define MID(l, r)   (l + r) >> 1
#define Min(x, y)   (x) < (y) ? (x) : (y)
#define Max(x, y)   (x) < (y) ? (y) : (x)
#define E(x)        (1 << (x))
#define iabs(x)     (x) < 0 ? -(x) : (x)
#define OUT(x)  printf("%I64d\n", x)
#define lowbit(x)   (x)&(-x)
#define Read()  freopen("din.txt", "r", stdin)
#define Write() freopen("dout.txt", "w", stdout);#define M 150
#define N 4100007
using namespace std;struct node
{node *next[2];ll flag;
}*head;node H[N];
int h;
int n;
int bit[44];
ll a[100007];node *newnode()
{node *p = &H[h++];p->next[0] = NULL;p->next[1] = NULL;p->flag = 0;return p;
}
void insert(ll no)
{int i;CL(bit,0);for (i = 0; i <= 40; ++i){bit[i] = (1&(no>>i));}node *p = head;for (i = 40; i >= 0; --i){if (p->next[bit[i]] == NULL){p->next[bit[i]] = newnode();}p = p->next[bit[i]];}p->flag = no;
}
ll query(ll no)
{int i;CL(bit,0);for (i = 0; i <= 40; ++i){bit[i] = (1&(no>>i));}node *p = head;for (i = 40; i >= 0; --i){if (p->next[bit[i]^1]) p = p->next[bit[i]^1];else p = p->next[bit[i]];}return (no^p->flag);
}
int main()
{int i;scanf("%d",&n);h = 0;head = newnode();ll sum = 0;ll ans = 0;for (i = 0; i < n; ++i){scanf("%I64d",&a[i]);sum ^= a[i];insert(sum);ans = max(sum,ans);}sum = 0;for (i = n - 1; i >= 0; --i){sum ^= a[i];ans = max(ans,query(sum));}printf("%I64d\n",ans);return 0;
}

转载于:https://www.cnblogs.com/E-star/archive/2013/03/22/2976098.html

Codeforces Round #173 (Div. 2)相关推荐

  1. Codeforces Round #797 (Div. 3)无F

    Codeforces Round #797 (Div. 3)无F 这打的也太屎了,白天把G补了才知道简单的很,但f还是没头绪呜呜呜 Problem - A - Codeforces Given the ...

  2. Codeforces Round #506 (Div. 3)

    Codeforces Round #506 (Div. 3) 实习期间事不多,对div3 面向题解和数据编程了一波 A. Many Equal Substrings 题目链接 A题就是找后缀和前缀重合 ...

  3. Codeforces Round #563 (Div. 2)/CF1174

    Codeforces Round #563 (Div. 2)/CF1174 CF1174A Ehab Fails to Be Thanos 其实就是要\(\sum\limits_{i=1}^n a_i ...

  4. 构造 Codeforces Round #302 (Div. 2) B Sea and Islands

    题目传送门 1 /* 2 题意:在n^n的海洋里是否有k块陆地 3 构造算法:按奇偶性来判断,k小于等于所有点数的一半,交叉输出L/S 4 输出完k个L后,之后全部输出S:) 5 5 10 的例子可以 ...

  5. Codeforces Round #696 (Div. 2) (A ~ E)超高质量题解(每日训练 Day.16 )

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Codeforces Round #696 (Div. 2) (A ~ E)超高质量题解 比赛链接:h ...

  6. Codeforces Round #712 Div.2(A ~ F) 超高质量题解(每日训练 Day.15 )

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Codeforces Round #712 Div.2(A ~ F) 题解 比赛链接:https:// ...

  7. Codeforces Round #701 (Div. 2) A ~ F ,6题全,超高质量良心题解【每日亿题】2021/2/13

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 目录 A - Add and Divide B - Replace and Keep Sorted C ...

  8. Codeforces Round #700 (Div. 2) D2 Painting the Array II(最通俗易懂的贪心策略讲解)看不懂来打我 ~

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 整场比赛的A ~ E 6题全,全部题目超高质量题解链接: Codeforces Round #700 ...

  9. Codeforces Round #699 (Div. 2) F - AB Tree(贪心、树上DP)超级清晰,良心题解,看不懂来打我 ~

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Codeforces Round #699 (Div. 2) F - AB Tree Problem ...

  10. Codeforces Round #699 (Div. 2) (A ~ F)6题全,超高质量良心题解【每日亿题】2021/2/6

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Codeforces Round #699 (Div. 2) (A.B.C)[每日亿题]2021/2/ ...

最新文章

  1. 利用c语言找出输入文本最长的一行
  2. Google C++命名规范
  3. Stixel_World(single)学习笔记
  4. springboot-嵌入式Servlet容器(Tomcat)源码分析以及容器切换
  5. 实战06_SSM整合ActiveMQ支持多种类型消息
  6. 小米一元流量magisk_小米推出5G定制电话卡,资费月49元起,成最便宜5G手机套餐!...
  7. 运筹学在不同环境下的决策 -- 学习记录
  8. python 可控制深度遍历文件夹
  9. 安装nvm下载node,npm以及配置的全过程。解析npm下载包使用 -v指令 发现下载的包不存在的原因。
  10. 几个轻巧好用的代码检查工具!
  11. Navicat for MySQL 12.0.26 中文破解版 数据库管理工具
  12. Android P WMS addwindow流程
  13. c++builder:Project Project1.exe raised exception class EAccessViolation with message 'Access violati
  14. 2009级 华中科技大学 计算机学院 本科生名单,华中科技大学2009年本科特优生名单...
  15. openstack compute service list报错(HTTP 503)
  16. 快速排序和二分查找时间复杂度详解
  17. 从技术到应用实践 揭秘京东区块链布局全景
  18. 今日头条2018.8.12笔试题总结
  19. SpringCloud Alibaba Senta处理分布式事务
  20. python斐波那契数列第四十项_传统文化的数学基础(四)--论八卦、五行、天干地支、二十四节气、洛书与黄金分...

热门文章

  1. 投资人常用的忽悠用语!
  2. alien rpm deb,ubuntu下安装jdk过程及遇到的问题
  3. 程序员被公司辞退12天,前领导要求回公司讲清楚代码,结果懵了
  4. 一位程序员妹纸讲述她是如何拿到美团offer的?
  5. 别人工作2年半跳槽面试阿里,成功拿到offer,为什么你不可以?
  6. 微信技术总监周颢:一亿用户背后的架构秘密
  7. ArcGIS pro 发布地图服务(一)动态地图服务
  8. php中函数的类型提示和文件读取功能
  9. 027.3 反射技术 简单应用
  10. Spark源码分析之一:Job提交运行总流程概述