D - 粉碎叛乱

Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

Description

Adam and Eve play a card game using a regular deck of 52 cards. The rules are simple. The players sit on opposite sides of a table, facing each other. Each player gets k cards from the deck and, after looking at them, places the cards face down in a row on the table. Adam’s cards are numbered from 1 to k from his left, and Eve’s cards are numbered 1 to k from her right (so Eve’s i:th card is opposite Adam’s i:th card). The cards are turned face up, and points are awarded as follows (for each i ∈ {1, . . . , k}):

If Adam’s i:th card beats Eve’s i:th card, then Adam gets one point.

If Eve’s i:th card beats Adam’s i:th card, then Eve gets one point.

A card with higher value always beats a card with a
lower value: a three beats a two, a four beats a three and a two, etc.
An ace beats every card except (possibly) another ace.

If the two i:th cards have the same value, then the
suit determines who wins: hearts beats all other suits, spades beats all
suits except hearts, diamond beats only clubs, and clubs does not beat
any suit.

For example, the ten of spades beats the ten of diamonds but not the Jack of clubs.

This ought to be a game of chance, but lately Eve is
winning most of the time, and the reason is that she has started to use
marked cards. In other words, she knows which cards Adam has on the
table before he turns them face up. Using this information she orders
her own cards so that she gets as many points as possible.

Your task is to, given Adam’s and Eve’s cards, determine how many points Eve will get if she plays optimally.

 

Input

There will be several test cases. The first line of input will contain a
single positive integer N giving the number of test cases. After that
line follow the test cases.

Each test case starts with a line with a single positive
integer k <= 26 which is the number of cards each player gets. The
next line describes the k cards Adam has placed on the table, left to
right. The next line describes the k cards Eve has (but she has not yet
placed them on the table). A card is described by two characters, the
first one being its value (2, 3, 4, 5, 6, 7, 8 ,9, T, J, Q, K, or A),
and the second one being its suit (C, D, S, or H). Cards are separated
by white spaces. So if Adam’s cards are the ten of clubs, the two of
hearts, and the Jack of diamonds, that could be described by the line

TC 2H JD

 

Output

For each test case output a single line with the number of points Eve
gets if she picks the optimal way to arrange her cards on the table.

 

Sample Input

3
1
JD
JH
2
5D TC
4C 5H
3
2H 3H 4H
2D 3D 4D
 

Sample Output

1 1 2
 题解:坑,A竟然最大。。
代码:
 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define mem(x,y) memset(x,y,sizeof(x))
using namespace std;
typedef long long LL;
const int INF=0x3f3f3f3f;
int a[],b[];
char s[];
int getnum(){
int x=;
if(s[]=='A')x=;
else if(s[]=='T')x=;
else if(s[]=='J')x=;
else if(s[]=='Q')x=;
else if(s[]=='K')x=;
else if(s[]>=''&&s[]<='')x=s[]-'';
x=x*;
if(s[]=='C')x+=;
else if(s[]=='D')x+=;
else if(s[]=='S')x+=;
else if(s[]=='H')x+=;
return x;
}
int main(){
int T,N;
scanf("%d",&T);
while(T--){
scanf("%d",&N);
for(int i=;i<N;i++){
scanf("%s",s);
a[i]=getnum();
}
for(int i=;i<N;i++){
scanf("%s",s);
b[i]=getnum();
}
// for(int i=0;i<N;i++)printf("%d ",a[i]);puts("");
// for(int i=0;i<N;i++)printf("%d ",b[i]);puts("");
sort(a,a+N);sort(b,b+N);
int ans=;
for(int i=,j=;i<N&&j<N;){
if(b[i]>=a[j]){
i++;j++;ans++;
}
else i++;
}
printf("%d\n",ans);
}
return ;
}
F - 其他起义

Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu

Description

Painting some colored segments on a line, some previously painted segments may be covered by some the subsequent ones.

Your task is counting the segments of different colors you can see at last.

Input

The first line of each data set contains exactly one integer n, 1 <= n <= 8000, equal to the number of colored segments.

Each of the following n lines consists of exactly 3 nonnegative integers separated by single spaces:

x1 x2 c

x1 and x2 indicate the left endpoint and right endpoint of the segment, c indicates the color of the segment.

All the numbers are in the range [0, 8000], and they are all integers.

Input may contain several data set, process to the end of file.

Output

Each line of the output should contain a color index that can be seen
from the top, following the count of the segments of this color, they
should be printed according to the color index.

If some color can't be seen, you shouldn't print it.

Print a blank line after every dataset.

Sample Input

5
0 4 4
0 3 1
3 4 2
0 2 2
0 2 3
4
0 1 1
3 4 1
1 3 2
1 3 1
6
0 1 0
1 2 1
2 3 1
1 2 0
2 3 0
1 2 1

Sample Output

1 1
2 1
3 1

1 1

0 2
1 1

题解:暴力;

代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define mem(x,y) memset(x,y,sizeof(x))
using namespace std;
typedef long long LL;
const int INF=0x3f3f3f3f;
const int MAXN=1e6+;
int tree[MAXN],pre[MAXN];
int main(){
int N,x,y,z;
while(~scanf("%d",&N)){
mem(tree,-);mem(pre,);
for(int i=;i<N;i++){
scanf("%d%d%d",&x,&y,&z);
for(int j=x;j<y;j++)tree[j]=z;
}
for(int i=;i<=;i++){
if(tree[i]==-)continue;
pre[tree[i]]++;
while(tree[i+]==tree[i])i++;
}
for(int i=;i<=;i++){
if(!pre[i])continue;
printf("%d %d\n",i,pre[i]);
}
puts("");
}
return ;
}

 D - 粉碎叛乱F - 其他起义的更多相关文章

  1. 每日英语:China Destroys Six Tons of Confiscated Ivory

    BEIJING—Chinese government officials destroyed more than six tons of ivory that had been illegally s ...

  2. Mysql_以案例为基准之查询

    查询数据操作

  3. C#强力粉碎文件代码分享,升级中用到

    360的文件粉碎机还是很强大的,在我们客户端winform升级的时候,必须将有些文件进行强力删除后下载更新,如果删除失败很有可能整个 程序就无法更新到最新的版本,所以这里参考了网上的资料整理了一个文件 ...

  4. 在 C# 里使用 F# 的 option 变量

    在使用 C# 与 F# 混合编程的时候(通常是使用 C# 实现 GUI,F#负责数据处理),经常会遇到要判断一个 option 是 None 还是 Some.虽然 Option module 里有 i ...

  5. 如果你也会C#,那不妨了解下F#(7):面向对象编程之继承、接口和泛型

    前言 面向对象三大基本特性:封装.继承.多态.上一篇中介绍了类的定义,下面就了解下F#中继承和多态的使用吧.

  6. 如果你也会C#,那不妨了解下F#(2):数值运算和流程控制语法

    本文链接:http://www.cnblogs.com/hjklin/p/fs-for-cs-dev-2.html 一些废话 一门语言火不火,与语言本身并没太大关系,主要看语言的推广. 推广得好,用的 ...

  7. 使用F#开发ASP.NET Core应用程序

    .NET Core 里的F# 在.NET Core刚发布时,就已经添加了对F#的支持.但因为当时F#组件还不完整,而一些依赖包并没有放在Nuget上,而是社区自己放到MyGet上,所以在使用dotne ...

  8. 如果你也会C#,那不妨了解下F#(6):面向对象编程之“类”

    前言 面向对象的思想已经非常成熟,而使用C#的程序员对面向对象也是非常熟悉,所以我就不对面向对象进行介绍了,在这篇文章中将只会介绍面向对象在F#中的使用. F#是支持面向对象的函数式编程语言,所以你用 ...

  9. 如果你也会C#,那不妨了解下F#(5):模块、与C#互相调用

    F# 项目 在之前的几篇文章介绍的代码都在交互窗口(fsi.exe)里运行,但平常开发的软件程序可能含有大类类型和函数定义,代码不可能都在一个文件里.下面我们来看VS里提供的F#项目模板. F#项目模 ...

随机推荐

  1. SQL Server使用LIKE运算符进行匹配查询

    在查询的过程中,如果遇到不能明确的指明查询的限定条件时,就会用到LIKE运算符进行模式匹配查询.在查询时可以使用如下几个通配符: %:包含零个或多个字符的任意字符串 —(下划线):任何单个字符 []: ...

  2. loaded some nib but the view outlet was not set

    链接地址:http://www.cnblogs.com/TivonStone/archive/2012/04/20/2460116.html 当使用 initWithNibName 函数, 并使用 由 ...

  3. [LeetCode]题解(python):007-Reverse Integer

    题目来源: https://leetcode.com/problems/reverse-integer/ 题意分析: 这道题目很简单,就是将一个数反转,123变321,-123变321. 题目思路: ...

  4. 帝国cms7.2灵动标签万能教程

    学完本文,就完全能掌握帝国模板开发制作啦!这里只介绍sql语句调用方法(方便,快捷!) 灵动标签语法: [e:loop={,24,0}] 模板内容 [/e:loop] 详细解释:黄色部分:条件语句,即 ...

  5. 应用 Valgrind 发现 Linux 程序的内存问题

    如何定位应用程序开发中的内存问题,一直是 inux 应用程序开发中的瓶颈所在.有一款非常优秀的 linux 下开源的内存问题检测工具:valgrind,能够极大的帮助你解决上述问题.掌握 valgri ...

  6. Mac OS X Mavericks or Yosemite 安装Nginx、PHP、Mysql、phpMyAdmin

    翻译:http://blog.frd.mn/install-nginx-php-fpm-mysql-and-phpmyadmin-on-os-x-mavericks-using-homebrew/ 最 ...

  7. Spring-data-redis: 分布式队列

    Redis中list数据结构,具有"双端队列"的特性,同时redis具有持久数据的能力,因此redis实现分布式队列是非常安全可靠的.它类似于JMS中的"Queue&qu ...

  8. 动态链接库dll,静态链接库lib, 导入库lib

    转载地址:http://www.cnblogs.com/chio/archive/2008/08/05/1261296.html 目前以lib后缀的库有两种,一种为静态链接库(Static Libar ...

  9. 如何开始一个模块化可扩展的Web App(转)

    原文链接:http://avnpc.com/pages/start-a-modular-extensible-webapp 日志未经声明,均为AlloVince原创.版权采用『 知识共享署名-非商业性 ...

  10. UVAlive 2326 Moving Tables(贪心 + 区间问题)

    The famous ACM (Advanced Computer Maker) Company has rented a floor of a building whose shape is in ...