2022年天梯赛题目解析

#include <iostream>
using namespace std;
int main()
{
cout << "I'm gonna win! Today!" << endl;
cout << "2022-04-23" << endl;
return 0;
}

#include <iostream>
using namespace std;
int main()
{
int n , v;
cin >> n >> v;
cout << n / v;
return 0;
}


#include <iostream>
using namespace std;
int main()
{
int j , p , x1 , x2;
cin >> j >> p >> x1 >> x2;
if(x1 >= j || (x1 < j && x2 >= p)) cout << x1 << "-Y ";
else cout << x1 << "-N ";
if(x2 >= j|| (x2 < j && x1 >= p)) cout << x2 << "-Y\n";
else cout << x2 << "-N\n";
if(x1 >= j && x2 >= j) {
cout << "huan ying ru guan\n";
} else if(x1 < j && x2 < j) {
cout << "zhang da zai lai ba\n";
} else if(x1 < j && x2 >= p) {
printf("qing 2 zhao gu hao 1\n");
} else if(x2 < j && x1 >= p) {
printf("qing 1 zhao gu hao 2\n");
} else if(x1 >= j && x2 < j && x1 < p) {//一开始这里没考虑清楚,最后一分钟发现错误~
printf("1: huan ying ru guan\n");
} else if(x2 >= j && x1 < j && x2 < p) {
printf("2: huan ying ru guan\n");
}
return 0;
}


#include <iostream>
using namespace std;
long long f(int n)//最好写成long long , 防止数据溢出
{
long long t = 1;
for(int i = 1 ; i <= n ; ++i)
t *= i;
return t;
}
int main()
{
int a , b;
cin >> a >> b;
cout << f(a + b);
return 0;
}

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
using namespace std;
int num[10];
bool vis[10][10];
//vis[第i个面][第i个面的点数]:判断是否出现过
int main()
{
for(int i = 0 ; i < 6 ; ++i) cin >> num[i];
int n;
cin >> n;
while(n--) {
for(int i = 0 ; i < 6 ; ++i) {
vis[i][num[i]] = true;
//从大到小,保证每次点数最大
for(int j = 6 ; j >= 1 ; --j)
if(!vis[i][j]) {
num[i] = j;
break;
}
}
}
for(int i = 0 ; i < 6 ; ++i) cout << num[i] << " \n"[i == 5];
return 0;
}

#include <iostream>
using namespace std;
string f(string s)
{
string s0;
for (int i = 1 ; i < s.size(); i++)
if (s[i] % 2 == s[i-1] % 2)
s0 += max(s[i], s[i-1]);
return s0;
}
int main()
{
string s1 , s2;
cin >> s1 >> s2;
if(f(s1) == f(s2)) cout << f(s1);
else cout << f(s1) << endl << f(s2) << endl;
return 0;
}

#include <bits/stdc++.h>
//考试19分
using namespace std;
const int N = 1e4 + 9999;
bool vis[N][N];
int main()
{
int n , m , q , ans = 0;
cin >> n >> m >> q;
while(q--) {
int t , c;
cin >> t >> c;
if(t == 1) {
for(int i = 0 ; i < n ; ++i)
vis[i][c - 1] = true;
} else {
for(int i = 0 ; i < m ; ++i)
vis[c - 1][i] = true;
}
}
for(int i = 0 ; i < n ; ++i)
for(int j = 0 ; j < m ; ++j) {
if(vis[i][j]) continue;
++ans;
}
cout << ans;
return 0;
}
#include <bits/stdc++.h>
using namespace std;
set<pair<int , int>>st;
int main()
{
int n , m , q , ans = 0;
cin >> n >> m >> q;
while(q--) {
int t , c;
cin >> t >> c;
if(t == 1) {
for(int i = 1 ; i <= n ; ++i) {
if(!st.count({i , c})) ++ans;
st.insert({i , c});
}
} else {
for(int i = 1 ; i <= m ; ++i) {
if(!st.count({c , i})) ++ans;
st.insert({c , i});
}
}
}
cout << n * m - ans;
return 0;
}
经常使用)

#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;
typedef pair<int , int> pii;
multimap<int , int> m;
bool v1[300][105];
int main()
{
int n , k , s;
cin >> n >> k >> s;
while(n--) {
int t , p;
scanf("%d %d" , &t , &p);
if(t < 175) continue;
m.insert(make_pair(t , p));
}
int ans = 0 , ans1 = 0 , ans2 = 0;
for(int l = 0 ; l < k ; ++l) {
bool v2[300] = {false};
for(auto i = m.begin() ; i != m.end() ; ++i) {
if(i->y >= s && !v1[i->x][i->y] && m.count(i->x) > 1 && l != 0) {
++ans;
v1[i->x][i->y] = true;
continue;
}
if(!v2[i->x] && !v1[i->x][i->y]) {
++ans;
v2[i->x] = true;
v1[i->x][i->y] = true;
}
}
}
cout << ans<<endl;
return 0;
}
不能直接存储结构体(pair)作为键值),调试了很长时间~#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#define x first
#define y second
using namespace std;
typedef pair<int , int> pii;
vector<pii> v;
int main()
{
int n , k , s;
cin >> n >> k >> s;
while(n--) {
int t , p;
scanf("%d %d" , &t , &p);
if(t < 175) continue;
v.push_back({t , p});
}
sort(v.begin() , v.end());
int ans = 0;
while(k--) {
bool vis[300] = {false};
for(int i = 0 ; i < v.size() ; ++i) {
if(vis[v[i].x] && v[i].y < s) continue;
vis[v[i].x] = true;
++ans;
v.erase(v.begin() + i);
i = 0;
}
}
cout << ans;
return 0;
}
>175分的面试者,即需要两重循环来操作v.erase(v.begin() + i)i是从0开始到第i个,并且删除元素后容器里元素的下标改变所以每次删除都要将i置为0200ms,所以TLE#include <iostream>
#include <cstdio>
#include <unordered_map>
#define x first
#define y second
using namespace std;
unordered_map<int , int> m;
int main()
{
int n , k , s , ans = 0;
cin >> n >> k >> s;
while(n--) {
int t , p;
scanf("%d %d" , &t , &p);
if(t < 175) continue;
if(p >= s) {
++ ans;
continue;
}
++m[t];
}
for(auto i : m)
ans += i.y >= k ? k : i.y;
cout << ans;
return 0;
}
1.按照之前的思路两重循环TLE,所以得往一重循环的方向想
2. 题目的意思是(非常重要):
>=175分都有机会被录取>=s(该企业的面试分数线) , 直接被录取(天梯赛分数>=175)>=s(该企业的面试分数线)的面试者) , 即只能录取一个>=s(该企业的面试分数线) 除外)3.所以思路就很明确:
>=175的面试者(++ans) 和 天梯赛分数 < 175 (边输入边操作)批次k >= 某个分数的面试者的个数, 说明该分数的面试者全部被录取批次k < 某个分数的面试者的个数, 说明该分数的面试者部分被录取,录取了k个ans += i.y >= k ? k : i.y; , emmmm,有点贪心的思想
#include <iostream>
#include <set>
#include <unordered_map>
using namespace std;
set<string>st;
unordered_map<string , int> vis;
void f(string s) {
if(vis[s] == 2 || s == "00:00:00" || s == "23:59:59")
st.erase(s);
else
st.insert(s);
}
int main()
{
//卡输入输出,如果不解除缓存,就TLE(21)分
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n , k , j = 0;
cin >> n;
while(n-- ) {
char ch;
string s1 , s2;
cin >> s1 >> ch >> s2;
++vis[s1] , ++vis[s2];
f(s1) , f(s2);
}
if(!(vis["00:00:00"])) st.insert("00:00:00");
if(!(vis["23:59:59"])) st.insert("23:59:59");
for(auto i : st) {
++j;
cout << i;
j & 1 ? cout << " - " : cout << endl;
}
return 0;
}
00:00:00 和23:59:59)s1,字符'-', 和字符串s200:00:00 和23:59:59 , 这两个只要出现就删除00:00:00 和23:59:59 , 就添加TLE(21)分,因为每个区间间隔至少 1 秒,max(n) = 86400 / 2//解除缓存的模板
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
WINDWOS下[1e5的数据量]:
使用解除绑定的cout : 30.719000 秒 , 29.518000 秒 , 29.446000 秒
不使用解除绑定cout : 51.749000 秒 , 49.383000 秒 , 47.605000 秒
C++文件的printf : 84.962000 秒 , 76.131000 秒 , 77.639000 秒
C语言文件的printf : 29.776000 秒 , 29.327000 秒 , 29.862000 秒
我有一个字符串input="maybe(thisis|thatwas)some((nice|ugly)(day|night)|(strange(weather|time)))"Ruby中解析该字符串的最佳方法是什么?我的意思是脚本应该能够像这样构建句子:maybethisissomeuglynightmaybethatwassomenicenightmaybethiswassomestrangetime等等,你明白了......我应该一个字符一个字符地读取字符串并构建一个带有堆栈的状态机来存储括号值以供以后计算,还是有更好的方法?也许为此目的准备了一个开箱即用的库?
我主要使用Ruby来执行此操作,但到目前为止我的攻击计划如下:使用gemsrdf、rdf-rdfa和rdf-microdata或mida来解析给定任何URI的数据。我认为最好映射到像schema.org这样的统一模式,例如使用这个yaml文件,它试图描述数据词汇表和opengraph到schema.org之间的转换:#SchemaXtoschema.orgconversion#data-vocabularyDV:name:namestreet-address:streetAddressregion:addressRegionlocality:addressLocalityphoto:i
我正在使用ruby1.9解析以下带有MacRoman字符的csv文件#encoding:ISO-8859-1#csv_parse.csvName,main-dialogue"Marceu","Giveittohimóhe,hiswife."我做了以下解析。require'csv'input_string=File.read("../csv_parse.rb").force_encoding("ISO-8859-1").encode("UTF-8")#=>"Name,main-dialogue\r\n\"Marceu\",\"Giveittohim\x97he,hiswife.\"\
简而言之错误:NOTE:Gem::SourceIndex#add_specisdeprecated,useSpecification.add_spec.Itwillberemovedonorafter2011-11-01.Gem::SourceIndex#add_speccalledfrom/opt/local/lib/ruby/site_ruby/1.8/rubygems/source_index.rb:91./opt/local/lib/ruby/gems/1.8/gems/rails-2.3.8/lib/rails/gem_dependency.rb:275:in`==':und
我正在使用ruby2.1.0我有一个json文件。例如:test.json{"item":[{"apple":1},{"banana":2}]}用YAML.load加载这个文件安全吗?YAML.load(File.read('test.json'))我正在尝试加载一个json或yaml格式的文件。 最佳答案 YAML可以加载JSONYAML.load('{"something":"test","other":4}')=>{"something"=>"test","other"=>4}JSON将无法加载YAML。JSON.load("
我想用Nokogiri解析HTML页面。页面的一部分有一个表,它没有使用任何特定的ID。是否可以提取如下内容:Today,3,455,34Today,1,1300,3664Today,10,100000,3444,Yesterday,3454,5656,3Yesterday,3545,1000,10Yesterday,3411,36223,15来自这个HTML:TodayYesterdayQntySizeLengthLengthSizeQnty345534345456563113003664354510001010100000344434113622315
我使用的第一个解析器生成器是Parse::RecDescent,它的指南/教程很棒,但它最有用的功能是它的调试工具,特别是tracing功能(通过将$RD_TRACE设置为1来激活)。我正在寻找可以帮助您调试其规则的解析器生成器。问题是,它必须用python或ruby编写,并且具有详细模式/跟踪模式或非常有用的调试技术。有人知道这样的解析器生成器吗?编辑:当我说调试时,我并不是指调试python或ruby。我指的是调试解析器生成器,查看它在每一步都在做什么,查看它正在读取的每个字符,它试图匹配的规则。希望你明白这一点。赏金编辑:要赢得赏金,请展示一个解析器生成器框架,并说明它的
我有这样的HTML代码:Label1Value1Label2Value2...我的代码不起作用。doc.css("first").eachdo|item|label=item.css("dt")value=item.css("dd")end显示所有首先标记,然后标记标签,我需要“标签:值” 最佳答案 首先,您的HTML应该有和中的元素:Label1Value1Label2Value2...但这不会改变您解析它的方式。你想找到s并遍历它们,然后在每个你可以使用next_element得到;像这样:doc=Nokogiri::HTML(
我想禁用HTTP参数的自动XML解析。但我发现命令仅适用于Rails2.x,它们都不适用于3.0:config.action_controller.param_parsers.deleteMime::XML(application.rb)ActionController::Base.param_parsers.deleteMime::XMLRails3.0中的等价物是什么? 最佳答案 根据CVE-2013-0156的最新安全公告你可以将它用于Rails3.0。3.1和3.2ActionDispatch::ParamsParser::
下面是我用来从应用程序中解析CSV的代码,但我想解析位于AmazonS3存储桶中的文件。当推送到Heroku时它也需要工作。namespace:csvimportdodesc"ImportCSVDatatoInventory."task:wiwt=>:environmentdorequire'csv'csv_file_path=Rails.root.join('public','wiwt.csv.txt')CSV.foreach(csv_file_path)do|row|p=Wiwt.create!({:user_id=>row[0],:date_worn=>row[1],:inven