2190: 【USACO】Farmer John has no Large Brown Cow

时间限制: 1.000 Sec  内存限制: 64 MB
提交: 16  解决: 12
[命题人:][下载数据: 70]

提交状态报告

题目描述

Farmer John likes to collect as many different types of cows as possible. In fact, he has collected almost every conceivable type of cow, except for a few, written on a short list of N lines (1 <= N <= 100). The list looks like this: Farmer John has no large brown noisy cow. Farmer John has no small white silent cow. Farmer John has no large spotted noisy cow. Each item in the list describes a missing cow in terms of a short list of adjectives, and each item contains the same number of adjectives (3, in this case). The number of adjectives per line will be in the range 2..30. Farmer John has a cow fitting every other possible adjective combination not on his list. In this example, the first adjective can be large or small, the second can be brown, white, or spotted, and the third can be noisy or silent. This gives 2 x 3 x 2 = 12 different combinations, and Farmer John has a cow fitting each one, except for those specifically mentioned on his list. In this example, a large, white, noisy cow is one of his 9 cows. Farmer John is certain that he has at most 1,000,000,000 cows. If Farmer John lists his cows in alphabetical order, what is the Kth cow in this list? Partial credit opportunities: In the 10 test cases for this problem, cases 1..4 involve at most two adjectives per line in Farmer John's list. In cases 1..6, each adjective will have exactly two possible settings (in all other cases, each adjective will have between 1 and N possible settings).

输入

* Line 1: Two integers, N and K. * Lines 2..1+N: Each line is a sentence like "Farmer John has no large spotted noisy cow.". Each adjective in the sentence will be a string of at most 10 lowercase letters. You know you have reached the end of the sentence when you see the string "cow." ending with a period.

输出

* Line 1: The description of the Kth cow on the farm.

样例

输入  复制

3 7 Farmer John has no large brown noisy cow. Farmer John has no small white silent cow. Farmer John has no large spotted noisy cow.

输出  复制

small spotted noisy

提示

INPUT DETAILS: The input matches the sample given in the problem statement above. Farmer John would like to know the 7th cow on his farm, when listed in alphabetical order. OUTPUT DETAILS: Farmer john has cows matching the following descriptions, listed in alphabetical order: large brown silent large spotted silent large white noisy large white silent small brown noisy small brown silent small spotted noisy small spotted silent small white noisy The 7th cow in this list is described as "small spotted noisy".

来源/分类

USACO 2013 November Bronze

#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;struct Letr {int group;string adj;bool operator < (const Letr &a) const {return adj < a.adj;}
};
Letr adj[30005];
vector<string>str[350];
int n , k , num , top = 0 , cnt[350] , qc[350][1050], knum[350] , pnum[350], flag;
string gro[350][1050];int jud(string s) {if(s != "Farmer" && s != "John" && s != "has" && s != "no" && s != "cow.")return 1;return 0;
}void update(int t) {for(int i=1; i<num; i++) {int sum = 0;for(int j=1; j<=cnt[i]; j++) {sum += qc[i][j];if(sum == t) {knum[i] = j;for(int l=i+1; l<=num; l++)knum[l] = cnt[i];return ;}if(sum > t) {knum[i] = (j-1<1)?1:j;t -= (qc[i][(j-1<1)?1:(j-1)]*(j-1));break;      }}}knum[num] = t;
} void sol(int x[] , int y[]) {for(int i=1; i<=num; i++) {if(x[i] > y[i])return;if(x[i] < y[i]) {flag = 1;return;     }}flag = 1;
}int main() {scanf("%d%d",&n,&k);for(int i=1; i<=n; i++) {string s;num = 0;while(1) {cin>>s;if(jud(s)) {num++;str[i].push_back(s);adj[++top].adj = s;adj[top].group = num;}if(s == "cow.")break;}}sort(adj , adj+top+1);for(int i=1; i<=top; i++) {if(adj[i].adj == adj[i-1].adj && adj[i].group == adj[i-1].group)continue;gro[adj[i].group][++cnt[adj[i].group]] = adj[i].adj;}for(int i=1; i<=n; i++)qc[num][i] = 1;for(int i=num-1; i>=1; i--)for(int j=1; j<=n; j++)qc[i][j] = qc[i+1][j]*cnt[i+1];update(k);for(int i=1; i<=n; i++) {flag = 0;for(int j=0; j<str[i].size(); j++) {for(int l=1; l<=cnt[j+1]; l++) {if(str[i][j] == gro[j+1][l]) {pnum[j+1] = l;break;}}       }sol(pnum , knum);if(flag) {k++;update(k);}}for(int i=1; i<=num; i++)cout<<gro[i][knum[i]]<<" ";return 0;
}

2190: 【USACO】Farmer John has no Large Brown Cow相关推荐

  1. [USACO13NOV]Farmer John has no Large Brown Cow【状压 / 模拟】

    Pro Luogu3087 Sol 哇哇哇,昨晚调了一个小时没调出来,今天早上调了一会就出来了坑点不算很多,只是我比较粗心-- 拿到题,一眼肯定想到和排列组合有关的知识,其实用到的也不是太多,首先对于 ...

  2. jzoj 1594: 【USACO】The Chivalrous Cow(骑士牛)( 待加入)

    1594: [USACO] 题目描述 Farmer John traded one of his cows for a cow that Farmer Don called 'The Knight' ...

  3. 2191: 【USACO】Crowded Cows

    2191: [USACO]Crowded Cows 时间限制: 1.000 Sec  内存限制: 64 MB 提交: 26  解决: 19 [命题人:][下载数据: 90] 提交状态报告 题目描述 ...

  4. 【USACO】iCow播放器

    [USACO]iCow播放器 题目: 被无止境的农活压榨得筋疲力尽后,Farmer John打算用他在MP3播放器市场新买的iCow来听些音乐,放松一下.FJ的iCow里存了N(1 <= N & ...

  5. 【USACO】双数? 单数?

    [USACO]双数? 单数? 题意分析: 这道题的题意还是比较明了的,就是读入一个很大的数,判断它是奇数还是偶数. 解题思路: 因为我们知道,任意一个数最后一位是奇数,这个数就是奇数,偶数,同理. 这 ...

  6. 1584: 【USACO】双数? 单数?

    1584: [USACO]双数? 单数? 时间限制: 1.000 Sec  内存限制: 64 MB 提交: 6305  解决: 2829 [命题人:][下载数据: 70] 提交状态报告 题目描述 B ...

  7. 【USACO】贝茜的晨练计划

    [USACO]贝茜的晨练计划 题目: 奶牛们打算通过锻炼来培养自己的运动细胞,作为其中的一员,贝茜选择的运动方式是每天进行N(1 <= N <= 10,000)分钟的晨跑. 在每分钟的开始 ...

  8. JZOJ__Day 10:【普及模拟】【USACO】iCow播放器

    题目描述 被无止境的农活压榨得筋疲力尽后,Farmer John打算用他在MP3播放器市场新买的iCow来听些音乐,放松一下.FJ的iCow里存了N(1 <= N <= 1,000)首曲子 ...

  9. JZOJ__Day 10:【普及模拟】【USACO】横幅

    题目描述 Bessie结束了国外长途旅游回来.为了迎接她的归来,Farmer John准备在牧场给她挂起一个"Welcome Home"的横幅.横幅会挂在两个柱子间的长度介于L1. ...

最新文章

  1. DNS Serv管理与维护
  2. 快速多尺度人脸检测--Multi-Scale Fully Convolutional Network for Fast Face Detection
  3. 对request.getSession(false)的理解(附程序员常疏忽的一个漏洞)--转
  4. [Intellij] 软件设置和常用快捷键
  5. 【原】iOS:手把手教你发布代码到CocoaPods(Trunk方式)
  6. 接收字节流_Java之IO流、属性配置文件
  7. css3学习下...
  8. python ftp编程_【编程】Python FTP
  9. 机器人环境感知算法发展概述
  10. 栈的应用(进制转换)
  11. 清华大学2017计算机录取分数线,2017年清华大学录取分数线
  12. 图形绘制——pygame之旅
  13. JDK和JRE安装与下载
  14. 等保2.0|二级等保和三级等保要求对比
  15. NFT游戏开发NFT平台开发元宇宙对战游戏开发三国版元宇宙NFT游戏
  16. 正则表达式经典教程-转
  17. 智能优化算法:饥饿游戏搜索算法-附代码
  18. 巴曙松:寻找可持续的经济复苏
  19. BeatMark X for mac(fcpx音乐卡点神器)
  20. ubuntu中/usr目录下无法直接复制粘贴文件或目录

热门文章

  1. “百度杯”CTF比赛 九月场Upload 之菜刀的使用
  2. b s html模板,【B/S】HTML~CSS初识
  3. 公交查询系统c语言数据结构,公交路线查询系统(基于数据结构和C语言)
  4. kubernetes组件_Service_普通Service和无头Service
  5. 还在为写调查问卷发愁的你赶快来看看这个自动填写问卷(问卷星版)
  6. 图片尺寸px怎么转换成厘米?在线图片尺寸换算工具怎么用?
  7. 【雕虫小技第1篇】如何将Scratch项目(转换)打包为一个HTML文件
  8. 名不虚传。涵盖全微服务操作的Spring Cloud Alibaba PDF竟出自阿里
  9. YUV 422 10bit
  10. js实现天降字母打字小游戏