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 ...
随机推荐
- VSPackge插件系列:常用IDE功能的封装
继上一篇VSPackge插件系列简单介绍如何正确的获取DTE之后,就一直没发VSPackge插件系列的文章了,最近同事也想了解如何在代码中与VS交互,特发一篇文章示例一些简单功能是如何调用,也以备以后 ...
- 基于ubuntu和windows连接
对于ubuntu和centos安装软件是不一样的 对于ubuntu是 apt-get install +软件名字 但是对于centos是 yum install +软件名字 所以ubunu远程连接 ...
- 基于 JQUERY 网页 banner
demo.html <html> <head> <title>demo</title> <link href="css/PaPaBann ...
- 【Objective-C】4-空指针和野指针
一.什么是空指针和野指针 1.空指针 1> 没有存储任何内存地址的指针就称为空指针(NULL指针) 2> 空指针就是被赋值为0的指针,在没有被具体初始化之前,其值为0. 下面两个都是空指针 ...
- JavaScript高级程序设计(第三版)学习笔记8、9、10章
第8章,BOM BOM的核心对象是window,具有双重角色,既是js访问浏览器的一个接口,又是ECMAScript规定的Global对象.因此,在全局作用域中声明的函数.变量都会变成window对象 ...
- 常用ASP函数的封装
做ASP开发常常需要用到一些小功能,这些功能通常我们都会封装成函数来使用,本教程提供了许多我们经常用到的ASP函数. <% '所有功能函数名如下: ' StrLength(str) 取得字符串长 ...
- JNI的一些使用
1.简介 Java Native Interface(JNI) 有时候我们必须要调用本地代码c/c++来克服java中的内存管理和性能限制.java支持通过Java Native Interface( ...
- 【html】【15】特效篇--分页
下载参考: http://aspx.sc.chinaz.com/query.aspx?keyword=%E5%88%86%E9%A1%B5&classID=&page=1 实例: h ...
- C语言变参函数/Variadic fucntion
几个重要的 宏/类型 定义 Macros Defined in header <stdarg.h> va_start enables access to variadic function ...
- async:false同步请求,浏览器假死
// 异步请求导致数据错乱 // function get_num(){ // $("input[name='monitor']").eq(1).attr('checked',tr ...