文章目录
补题链接:https://codeforces.com/gym/102900
https://ac.nowcoder.com/acm/contest/9925/
G. Fibonacci
time limit per test1 second
memory limit per test1024 megabytes
inputstandard input
outputstandard output
In mathematics, the Fibonacci numbers, commonly denoted as fn, is a sequence such that each number is the sum of the two preceding numbers, starting with 1 and 1. That is, f1=1,f2=1 and fn=fn−2+fn−1 (n≥3).
Thus, the beginning of the sequence is 1,1,2,3,5,8,13,21,… .
Given n, please calculate ∑ni=1∑nj=i+1g(fi,fj), where g(x,y)=1 when x⋅y is even, otherwise g(x,y)=0.
Input
The only line contains one integer n (1≤n≤109).
Output
Output one number – ∑ni=1∑nj=i+1g(fi,fj).
Examples
inputCopy
3
outputCopy
2
inputCopy
10
outputCopy
24
inputCopy
100
outputCopy
2739
题意:
思路:
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
int main(){
LL n; cin>>n;
LL odd = n/3*2+n%3; //奇数个数
cout<<n*(n-1)/2-odd*(odd-1)/2<<"\n";
return 0;
}
M. Gitignore
time limit per test1 second
memory limit per test1024 megabytes
inputstandard input
outputstandard output
Your git project (you don’t need to be familiar with git to solve this problem) has some files that should be ignored from synchronizing. You need to calculate the minimum number of lines needed for gitignore.
Formally, your project is a folder. A folder can have files and sub folders. There are no empty folders (i.e. folders without any files or sub folders inside). Initially, the git software will synchronize all the files in your project. However, you can specify some files and folders in the settings (which is called gitignore) to exclude them from synchronizing. For each line in gitignore, you can specify either a file or all the files in a folder. You can not ignore the whole project folder (i.e. an empty line in gitignore).
You are given paths for all the files in the project and whether they should be ignored or shouldn’t. Your task is to calculate the minimum number of lines for gitignore.
Input
The input contains several test cases. The first line contains a single positive integer T which is the number of test cases. For each test case, you are first given two non-negative numbers n and m. And then n non-empty lines of file paths that should be ignored, and m non-empty lines of file paths that should not be ignored.
The paths are strings containing lower-cased English alphabets and slashes (‘/’) only. Slashes are used to separate folders, sub folders and file name. For exapmle, “a/b/c/d” indicates folder “a” in the project folder, folder “b” in folder “a”, folder “c” in “b” and file “d” in folder “c”. All the paths are valid, specifically:
The path is non-empty and it always indicates a file (i.e. the path does not end with a slash).
The path does not start with a slash.
Folder names and file names are non-empty (i.e. there are no consecutive slashes).
File paths are always unique (i.e. all the paths in a test case are different).
In a folder, no sub folders and files share the same names. For example, there won’t be two files “a/b/a” and “a/b/a/d” in one test case. However, files “a/b/a” and “a/b/b” are allowed.
1≤n+m≤100 holds and in the whole input there are no more than 1,000 characters in file paths (i.e. the sum of lengths of file path strings in the whole input file is no more than 1,000).
Output
T lines of non-negative integers, the minimum number of gitignore lines for each test case.
Example
inputCopy
2
3 0
data/train
data/test
model
3 1
data/train
data/test
model
data/sample
outputCopy
2
3
Note
In the first sample test case, the corresponding gitignore file contains 2 lines: a folder line “data/” and a file name “model”.
In the second sample test case, the corresponding gitignore file contains 3 file lines: “data/train”, “data/test” and “model”.
题意:
思路:
#include<bits/stdc++.h>
using namespace std;
string s[110];
int main(){
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int T; cin>>T;
while(T--){
int n, m; cin>>n>>m;
map<string, int>mp;
int ans = n;
for(int i = 1; i <= n+m; i++){
cin>>s[i];
string tmp = "";
for(char ch : s[i]){
if(ch!='/')tmp += ch;
else{
if(i<=n)mp[tmp] = 0;
else mp[tmp] = 1;
}
}
}
for(int i = 1; i <= n; i++){
string tmp = "";
for(char ch : s[i]){
if(ch!='/')tmp += ch;
else{
if(mp[tmp]==1)continue;
else if(mp[tmp]==0)mp[tmp] = 2;
else if(mp[tmp]==2){
ans--;
break;
}
}
}
}
cout<<ans<<"\n";
}
return 0;
}
B. Mine Sweeper II
time limit per test1 second
memory limit per test1024 megabytes
inputstandard input
outputstandard output
A mine-sweeper map X can be expressed as an n×m grid. Each cell of the grid is either a mine cell or a non-mine cell. A mine cell has no number on it. Each non-mine cell has a number representing the number of mine cells around it. (A cell is around another cell if they share at least one common point. Thus, every cell that is not on the boundary has 8 cells around it.) The following is a 16×30 mine-sweeper map where a flagged cell denotes a mine cell and a blank cell denotes a non-mine cell with number 0.
Given two mine-sweeper maps A,B of size n×m, you should modify at most ⌊nm2⌋ (i.e. the largest nonnegative integer that is less than or equal to nm2) cells in B (from a non-mine cell to a mine cell or vice versa) such that the sum of numbers in the non-mine cells in A and the sum of numbers in the non-mine cells in B are the same. (If a map has no non-mine cell, the sum is considered as 0.)
If multiple solutions exist, print any of them. If no solution exists, print “-1” in one line.
Input
The first line contains two integers n,m(1≤n,m≤1000), denoting the size of given mine-sweeper maps.
The i-th line of the following n lines contains a length-m string consisting of “.” and “X” denoting the i-th row of the mine-sweeper map A. A “.” denotes for a non-mine cell and an “X” denotes for a mine cell.
The i-th line of the following n lines contains a length-m string consisting of “.” and “X” denoting the i-th row of the mine-sweeper map B. A “.” denotes for a non-mine cell and an “X” denotes for a mine cell.
Output
If no solution exists, print “-1” in one line.
Otherwise, print n lines denoting the modified mine-sweeper map B. The i-th line should contain a length-m string consisting of “.” and “X” denoting the i-th row of the modified map B. A “.” denotes for a non-mine cell and an “X” denotes for a mine cell.
Please notice that you need not print the numbers on non-mine cells since these numbers can be determined by the output mine-sweeper map.
Example
inputCopy
2 4
X…X
X.X.
X.X.
.X…
outputCopy
X.XX
.X…
Note
We modify one cell in B. Then the sums of the numbers on non-mine cells in A and B both equal 10.
题意:
思路:
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1010;
char a[maxn][maxn], b[maxn][maxn];
int main(){
int n, m; cin>>n>>m;
for(int i = 1; i <= n; i++)cin>>a[i]+1;
for(int i = 1; i <= n; i++)cin>>b[i]+1;
int cnt = 0;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++){
if(a[i][j] != b[i][j])cnt++;
}
}
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++){
if(cnt<n*m/2)cout<<a[i][j];
else{
cout<<(a[i][j]=='X' ? '.' : 'X');
}
}
cout<<"\n";
}
return 0;
}
D. Walker
time limit per test1 second
memory limit per test1024 megabytes
inputstandard input
outputstandard output
As a world-famous traveler, Prof. Pang’s research interest is to travel as many places as possible in his life.
We have a segment [0,n]. There are two travelers on it. The first one is on position p1 with velocity v1 (which means s/he can walk v1 unit on the segment per second). The second one is on position p2 with velocity v2.
From their respective beginning points, travelers can walk on the segment. They cannot walk outside the segment. Whenever they want to change their direction, they can turn around immediately.
Please help Prof. Pang to calculate the minimum possible time by which every position of the segment is passed by at least one traveler.
Input
The first line contains one integer test (1≤test≤10000) – the number of test cases.
The i-th of the next test lines contains five numbers n,p1,i,v1,i,p2,i,v2,i (0<n≤10000, 0≤p1,i,p2,i≤n, 0.001≤v1,i,v2,i≤1000). All numbers have at most 3 digits after the decimal point.
Output
For each test case, we should output one number – the minimum time that every position of the segment is passed by at least one traveler.
Your answer is considered correct if its absolute or relative error does not exceed 10−6.
Example
inputCopy
2
10000.0 1.0 0.001 9999.0 0.001
4306.063 4079.874 0.607 1033.423 0.847
outputCopy
5001000.0000000000
3827.8370013755
题意:
思路:
ans=max((n-d1)/v1,d2/v2)ans=min((min(d1,n-d1)+n)/v1,(min(d2,n-d2)+n)/v2)#include<bits/stdc++.h>
using namespace std;
double eps = 1e-9;
double n, d1, v1, d2, v2;
double check(double mid){ //判断mid时间能否跑完
double p1 = max(mid*v1-2*d1, (mid*v1-d1)/2)+d1;
double p2 = max(mid*v2-2*(n-d2), (mid*v2-(n-d2))/2)+(n-d2);
return p1+p2>=n;
}
int main(){
int T; cin>>T;
while(T--){
cin>>n>>d1>>v1>>d2>>v2;
if(d1 > d2){ swap(d1, d2); swap(v1, v2); }
double ans = 0;
//往两边走
double x1 = min(n-d1, d1)+n, x2 = min(n-d2, d2)+n;
ans = min(x1/v1, x2/v2);
//相向而行
ans = min(ans, max((n-d1)/v1, d2/v2));
//反向而行, 二分时间
double l = max(d1/v1, (n-d2)/v2), r = ans;
while(abs(r-l) > eps){
double mid = (l+r)/2;
if(!check(mid))l = mid;
else {
r = mid, ans = min(ans, mid);
}
}
printf("%.10lf\n", ans);
}
return 0;
}
I. Sky Garden
time limit per test1 second
memory limit per test1024 megabytes
inputstandard input
outputstandard output
Prof. Du and Prof. Pang plan to build a sky garden near the city of Allin. In the garden, there will be a plant maze consisting of straight and circular roads.
On the blueprint of the plant maze, Prof. Du draws n circles indicating the circular roads. All of them have center (0,0). The radius of the i-th circle is i.
Meanwhile, Prof. Pang draws m lines on the blueprint indicating the straight roads. All of the lines pass through (0,0). Each circle is divided into 2m parts with equal lengths by these lines.
Let Q be the set of the n+m roads. Let P be the set of all intersections of two different roads in Q. Note that each circular road and each straight road have two intersections.
For two different points a∈P and b∈P, we define dis({a,b}) to be the shortest distance one needs to walk from a to b along the roads. Please calculate the sum of dis({a,b}) for all {a,b}⊆P.
Input
The only line contains two integers n,m (1≤n,m≤500).
Output
Output one number – the sum of the distances between every pair of points in P.
Your answer is considered correct if its absolute or relative error does not exceed 10−6.
Examples
inputCopy
1 2
outputCopy
14.2831853072
inputCopy
2 3
outputCopy
175.4159265359
Note
dis(p1,p2)=dis(p2,p3)=dis(p3,p4)=dis(p1,p4)=π2
dis(p1,p5)=dis(p2,p5)=dis(p3,p5)=dis(p4,p5)=1
dis(p1,p3)=dis(p2,p4)=2
题意:
思路:
#include<bits/stdc++.h>
using namespace std;
const double pi = acos(-1);
int main(){
double n, m; cin>>n>>m;
//本层1点到本层其余所有点的距离和,本层1点到本层及内部层所有点的距离和。
double point[1500], cir[1500], hu = pi/m;
double res = 0;
if(m > 1)res += n*(n+1)*m; //圆心
for(int i = 1; i <= n; i++){ //层
for(int j = 1; j < m; j++){ //到(左半圆)
point[i] += min(i*2.0, hu*j*i); //2次半径或走弧
}
point[i] *= 2; //到(左半圆)
point[i] += 2*i; //到对称点(走直径)
res += point[i]*m; //m个点值都一样的
res += ((i-1)*2*m+cir[i-1])*2*m; //(内层1点到所有内部点的距离+层之间的距离)*本层点数
cir[i] = cir[i-1]+(i-1)*2*m+point[i];//内层1点到所有点间的距离+层之间的距离+到本层所有点的距离
}
printf("%.10lf\n", res);
return 0;
}
作为新的阿里云用户,您可以50免费试用多种优惠,价值高达1,700美元(或8,500美元)。这将让您了解和体验阿里云平台上提供的一系列产品和服务。如果您以个人身份注册免费试用,您将获得价值1,700美元的优惠。但是,如果您是注册公司,您可以选择企业免费试用,提交基本信息通过企业实名注册验证,即可开始价值$8,500的免费试用!本教程介绍了如何设置您的帐户并使用您的免费试用版。关于免费试用在我们开始此试用之前,您还必须遵守以下条款和条件才能访问您的免费试用:只有在一年内创建的账户才有资格获得阿里云免费试用。通过此免费试用优惠,用户可以免费试用免费试用活动页面上列出的每种产品一次。如果您有多个帐
我知道还有其他相同的问题,但他们没有解决我的问题。我不断收到错误:Aws::Errors::MissingRegionErrorinBooksController#create,缺少区域;使用:region选项或将区域名称导出到ENV['AWS_REGION']。但是,这是我的配置开发.rb:config.paperclip_defaults={storage::s3,s3_host_name:"s3-us-west-2.amazonaws.com",s3_credentials:{bucket:ENV['AWS_BUCKET'],access_key_id:ENV['AWS_ACCE
技术选型1,前端小程序原生MINA框架cssJavaScriptWxml2,管理后台云开发Cms内容管理系统web网页3,数据后台小程序云开发云函数云开发数据库(基于MongoDB)云存储4,人脸识别算法基于百度智能云实现人脸识别一,用户端效果图预览老规矩我们先来看效果图,如果效果图符合你的需求,就继续往下看,如果不符合你的需求,可以跳过。1-1,登录注册页可以看到登录页有注册入口,注册页如下我们的注册,需要管理员审核,审核通过后才可以正常登录使用小程序1-2,个人中心页登录成功以后,我们会进入个人中心页我们在个人中心页可以注册人脸,因为我们做人脸识别签到,需要先注册人脸才可以进行人脸比对,进
我有以下文件结构:执行.rb图书馆我的类(class).rb在execute.rb我有下面的代码:#!/usr/bin/rubyrequire'lib/my_class'my_object=MyClass.newmy_object.some_method这是my_class.rb的代码:classMyClassdefsome_methodputs'OK'endend所以,我尝试运行execute.rb:rubyexecute.rb但是我收到这个错误:/home/vagrant/.rvm/rubies/ruby-2.0.0-p195/lib/ruby/site_ruby/2.0.0/ru
我的rails.pt-BR.yml上有这个:br:errors:format:!'%{attribute}%{message}'messages:restrict_dependent_destroy:one:"Nãoépossívelexcluiroregistropoisexisteum%{record}dependente"many:"Nãoépossívelexcluiroregistropoisexistem%{record}dependentes"在我的模型中,我有这个:has_many:entities,dependent::restrict_with_error每当res
我正在使用适用于Ruby的AWS开发工具包向Rails3应用程序发布消息和AWSSNS主题,如下所示:sns=AWS::SNS.newtopic=sns.topics['arn:aws:sns:eu-west-1:55555555555:my_topic']topic.publish("MESSAGE",:subject=>"SUBJECT")当我发布到“us-east-1”中的主题时,它按预期工作,但发布到“eu-west-1”区域中的主题时不起作用:AWS::SNS::Errors::InvalidParameter-Invalidparameter:TopicArn:使用AWSS
我想删除字符串中的非字母数字字符,但不删除国际字符,如重音字母。我也想保留空白。这是我目前所拥有的:the_string=the_string.gsub(/[^a-z0-9-]/i,'')虽然这确实会删除国际重音字母字符。我使用的解决方案:the_string=the_string.gsub(/[^\p{Alnum}\p{Space}-]/u,'')有效!谢谢。 最佳答案 您可以使用characterproperties这样做:the_string.gsub(/[^\p{Alnum}-]/,'')您可能还想使用\p{Space}来保
Spring国际化遇到的坑org.springframework.context.NoSuchMessageException:Nomessagefoundundercode‘xxx.xxxx’forlocale‘zh_CN’背景以前做的项目客户群体只有国内的客户,从来没有考虑过语言文字的问题。这次有一个需求的返回内容,要根据客户设置的语言返回不同的语言。尝试使用了以后,结果发现怎么都不好使,一直报的一个错误如下:org.springframework.context.NoSuchMessageException:Nomessagefoundundercode'user.name'forloc
只是在没有Rails环境的情况下让I18n工作有困难:irb>require'i18n'=>trueirb>I18n.load_path=Dir['/usr/lib/ruby/gems/1.9.1/gems/rails-i18n-0.6.6/rails/locale/en.yml']=>["/usr/lib/ruby/gems/1.9.1/gems/rails-i18n-0.6.6/rails/locale/en.yml"]irb>I18n.load_path+=Dir['/usr/lib/ruby/gems/1.9.1/gems/rails-i18n-0.6.6/rails/loca
如果我有这样的国际电话号码:0541754301我怎样才能格式化它来产生这样的东西:0541-754-301 最佳答案 您可以使用ActionView::Helpers::NumberHelper中的number_to_phone(number,options={})方法但是,文档指出此方法会将数字格式化为美国电话号码(例如(555)123-9876)。相反,您可以使用thispatch它增加了提供数字分组的能力::groupings-Specifiesalternategroupings(mustspecify3-elementa