Codeforces Round #329 div2
Problem_A(593A):
题意:
给n个单词, 每个单词由小写字母组成, 且长度<=1000.
组成一篇文章的要求是:
所有单词所用字母 <= 2
即最多只能有两个不同的字母。
求一篇文章的最长长度。
思路:
首先注意到单词都是由小写字母组成,小写字母只有26个, 所以可以转换一下:
如果一个单词所用字母超过2个, 那么我们舍弃它。因为它怎么都不可能会是一篇文章的组成部分。
如果没有超过两个, 那么找出这两个单词, 记录它的长度即可。
设f[i][j] = 只有字母为i + 'a' 和 j + 'a'的单词的长度,如果i == j则只有一个字母。
答案则为 max(f[i][j] + f[i][i] + f[j][j] (f[i][j] > 0), f[i][i] + f[j][j])
代码:
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <set>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <string>
#include <vector>
#include <fstream>
#include <iterator>
#include <iostream>
#include <algorithm>
using namespace std;
#define LL long long
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define eps 1e-6
#define MAXN 100010
#define MAXM 100
#define dd {cout<<"debug"<<endl;}
#define pa {system("pause");}
#define p(x) {printf("%d\n", x);}
#define pd(x) {printf("%.7lf\n", x);}
#define k(x) {printf("Case %d: ", ++x);}
#define s(x) {scanf("%d", &x);}
#define sd(x) {scanf("%lf", &x);}
#define mes(x, d) {memset(x, d, sizeof(x));}
#define do(i, x) for(i = 0; i < x; i ++)
#define dod(i, x, l) for(i = x; i >= l; i --)
#define doe(i, x) for(i = 1; i <= x; i ++)
struct node
{
LL l;
LL r;
};
int n;
LL x[];
bool flag;
struct node f[MAXN];
bool cmp(struct node x, struct node y)
{
if(((x.l - y.l < ) && (x.r - y.r > )) || ((x.l - y.l > ) && (x.r - y.r < )))
flag = true;
if(x.l == y.l) return x.r < y.r;
return x.l < y.l;
} int main()
{
flag = false;
scanf("%d", &n);
scanf("%I64d %I64d", &x[], &x[]);
LL k, b;
for(int i = ; i < n; i ++)
{
scanf("%I64d %I64d", &k, &b);
f[i].l = x[] * k + b;
f[i].r = x[] * k + b;
}
sort(f, f + n, cmp);
printf("%s\n", flag? "YES" : "NO");
return ;
}
Problem_B(593B):
题意:
给n条直线, 然后一个区间[x1, x2].
问, 这n条直线之中, 是否会有直线在[x1, x2]这个区间上有交点。
思路:
嗯....利用了奇淫技巧。
正常的思路是这样的:
先把每条直线在这个区间的值域[y1, y2]求出来。
然后会发现, 如果两条直线在这里有交点的话, 必然是对应两端点之差的符号相反。
即[y1, y2] [y3, y4]:
y1 - y3 < 0 && y2 - y4 > 0 或者
y1 - y3 > 0 && y2 - y4 < 0
贪心即可, 然而个人比较懒, 利用sort偷了个懒。
代码:
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <set>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <string>
#include <vector>
#include <fstream>
#include <iterator>
#include <iostream>
#include <algorithm>
using namespace std;
#define LL long long
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define eps 1e-6
#define MAXN 100010
#define MAXM 100
#define dd {cout<<"debug"<<endl;}
#define pa {system("pause");}
#define p(x) {printf("%d\n", x);}
#define pd(x) {printf("%.7lf\n", x);}
#define k(x) {printf("Case %d: ", ++x);}
#define s(x) {scanf("%d", &x);}
#define sd(x) {scanf("%lf", &x);}
#define mes(x, d) {memset(x, d, sizeof(x));}
#define do(i, x) for(i = 0; i < x; i ++)
#define dod(i, x, l) for(i = x; i >= l; i --)
#define doe(i, x) for(i = 1; i <= x; i ++)
struct node
{
LL l;
LL r;
};
int n;
LL x[];
bool flag;
struct node f[MAXN];
bool cmp(struct node x, struct node y)
{
if(((x.l - y.l < ) && (x.r - y.r > )) || ((x.l - y.l > ) && (x.r - y.r < )))
flag = true;
if(x.l == y.l) return x.r < y.r;
return x.l < y.l;
} int main()
{
flag = false;
scanf("%d", &n);
scanf("%I64d %I64d", &x[], &x[]);
LL k, b;
for(int i = ; i < n; i ++)
{
scanf("%I64d %I64d", &k, &b);
f[i].l = x[] * k + b;
f[i].r = x[] * k + b;
}
sort(f, f + n, cmp);
printf("%s\n", flag? "YES" : "NO");
return ;
}
Codeforces Round #329 div2的更多相关文章
- Codeforces Round #539 div2
Codeforces Round #539 div2 abstract I 离散化三连 sort(pos.begin(), pos.end()); pos.erase(unique(pos.begin ...
- 【前行】◇第3站◇ Codeforces Round #512 Div2
[第3站]Codeforces Round #512 Div2 第三题莫名卡半天……一堆细节没处理,改一个发现还有一个……然后就炸了,罚了一啪啦时间 Rating又掉了……但是没什么,比上一次好多了: ...
- Codeforces Round#320 Div2 解题报告
Codeforces Round#320 Div2 先做个标题党,骗骗访问量,结束后再来写咯. codeforces 579A Raising Bacteria codeforces 579B Fin ...
- Codeforces Round #564(div2)
Codeforces Round #564(div2) 本来以为是送分场,结果成了送命场. 菜是原罪 A SB题,上来读不懂题就交WA了一发,代码就不粘了 B 简单构造 很明显,\(n*n\)的矩阵可 ...
- Codeforces Round #361 div2
ProblemA(Codeforces Round 689A): 题意: 给一个手势, 问这个手势是否是唯一. 思路: 暴力, 模拟将这个手势上下左右移动一次看是否还在键盘上即可. 代码: #incl ...
- Codeforces Round #626 Div2 D,E
比赛链接: Codeforces Round #626 (Div. 2, based on Moscow Open Olympiad in Informatics) D.Present 题意: 给定大 ...
- Codeforces Round #329(Div2)
CodeForces 593A 题意:n个字符串,选一些字符串,在这些字符串中使得不同字母最多有两个,求满足这个条件可选得的最多字母个数. 思路:用c[i][j]统计文章中只有i,j对应两个字母出现的 ...
- CodeForces Round 192 Div2
This is the first time I took part in Codeforces Competition.The only felt is that my IQ was contemp ...
- Codeforces Round #329 (Div. 2) B. Anton and Lines 逆序对
B. Anton and Lines Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/593/pr ...
随机推荐
- 基于动态库的C++插件开发模型
基类为抽象类,在不同的动态库中实现不同的执行行为,但是每个动态库要提供2个统一的方法:1) baseClass * create(); 2) void destroy( baseClass* );,调 ...
- [转]Best way to sort a DropDownList in MVC3 / Razor using helper method
本文转自:http://stackoverflow.com/questions/7223185/best-way-to-sort-a-dropdownlist-in-mvc3-razor-using- ...
- [转载]删除所有的.svn文件夹
Windows 下,在DOS窗口中运行如下命令 dos 代码 for /r <你项目的路径> %i in (.svn) do rd /s /q %i Linux 下,可以先运行 显示出当前 ...
- [记录]Ubuntu下,使用Shell,简单替换有规律的文件名称
因工作中需要将Flash转为Html5,并且要有动画效果,我将Flash的组件导出Png序列,然后将Png序列拼接成一张雪碧图(Sprite),名字为在生成雪碧图可以排序,需要改成数字名称. 而名字是 ...
- WCF图片上传
WCF越来越流行,俺也在用,这是废话.项目中遇到需要图片上传,但是wcf上传会遇到一些异常,调试了N久,找了好多个解决方案才最终解决.代码直接贴上了 /// <summary> /// 笔 ...
- C#学习笔记15:字符串、文件、目录的操作方法
字符串:不可变性 String str=”abcdf”; 将字符串转换为char数组:ToCharArray(); Char[] ch=str.ToCharAarray(); 将char数组转换为字符 ...
- asp.net连接mysql数据库
方法一:使用MySQL推出的MySQL Connector/Net组件, 该组件是MySQL为ADO.NET访问MySQL数据库设计的.NET专用访问组件.完成该组件后,需要在项目中引用这个组件,也可 ...
- Oracle——事务(Transaction)
事务: 事务是指作为单个逻辑工作单元执行的一组相关操作. 这些操作要求全部完成或者全部不完成. 使用事务的原因:保证数据的安全有效. 事务的四个特点:(ACID) 1.原子性(Atomic):事务中所 ...
- 第一篇、C_高精度加法
简介: C语言中,整型占4字节,现在要计算两个100(假设)位以内的数想加,如果只是用整型去存储,明显就会越界.那么,我们有什么好的方法去完成这一操作呢? 1.用数组实现 数组中可以可以存储一定长度的 ...
- 3D Touch ? 木有6s,也阔以玩!!!
3D Touch 之 Peek & Pop 3D Touch 是iOS9之后专为 iPhone6s 机型加入的新特性,这一新技术移植于 Mac Book 上的 ForceTouch 更准确地说 ...