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 ...
随机推荐
- mapping 详解2(field datatypes)
基本类型 1. 字符串 字符串类型被分为两种情况:full-text 和 keywords. full-text 表示字段内容会被分析,而 keywords 表示字段值只能作为一个精确值查询. 参数: ...
- struts2的action从request获取参数值的几种方式
使用jquery框架的ajax能够方便的向后台传递参数,以$.post为例,参数有2种方式字符串和键值对:$.post(url, "name=aty&age=25")和$. ...
- 基于 JQUERY 网页 banner
demo.html <html> <head> <title>demo</title> <link href="css/PaPaBann ...
- Opencv——播放视频(带滚动条)
#include"highgui.h" #include"cv.h" ; CvCapture* g_capture = NULL; void onTrackba ...
- 未完待续的JAVA基础知识
第二卷 1.每个JAVA程序必须有一个main函数,但并非是每个类都有,main函数必须声明为static函数. 2.println与print之间的区别是换行与不换行. 3.在JAVA中,不想C/C ...
- powerdesigner 使用的几点问题
一.powerdesigner 没有DataBase?: powerdesigner 只有在选择物理模型PDM的时候才会出现数据库菜单. 二.PowerDesigner版本控制功能? 1.首先介绍一下 ...
- 深入了解webkit内核第一篇:JavaScript引擎深度解析
看到HorkeyChen写的文章<[WebKit] JavaScriptCore解析--基础篇(三)从脚本代码到JIT编译的代码实现>,写的很好,深受启发.想补充一些Horkey没有写到的 ...
- java集合 collection-list-LinkedList
import java.util.*; /* LinkedList:特有方法: addFirst(); addLast(); getFirst(); getLast(); 获取元素,但不删除元素.如果 ...
- Config spec rules for elements in subbranches
Quote from: Config spec rules for elements in subbranches The following is an example of a config s ...
- div高度自适应填充剩余部分
在乐学一百的开发过程中,遇到了一个小乐Fm开发,需要跟百度fm差不多,上边一个条,下边一个条,中间部分填充.但是还不能固定高度,因为屏幕的宽高都不一样...height:100%是不可行的.搜了一圈, ...