当前位置:网站首页>UCF(暑期团队赛二)
UCF(暑期团队赛二)
2022-07-06 05:11:00 【.Ashy.】
A . T9 Craziness(选择结构)
大意:
给出每个数字对应的字母,给出已存在的字典字符串,给出多组译码,如果一组译码中的每个译码都只有一个对应单词,则译出句子,若存在译码无法翻译则不翻译,若有译码对应多个单词则输出总共的情况数量;
思路
先把字典字符串译码,用一个 map 存好对应关系 ,用另一个 map 记下 每个译码对应单词的数量,然后判断即可;
#include<bits/stdc++.h>
using namespace std;
int n,m;
string s;
int cnt;
typedef long long ll;
map<string,string>mp1;
map<string,int>mp2;
vector<string>ve;
int main()
{
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>s;
int len=s.size();
string ss="";
for(int i=0;i<len;i++)
{
if(s[i]=='a'||s[i]=='b'||s[i]=='c') ss+='2';
if(s[i]=='d'||s[i]=='e'||s[i]=='f') ss+='3';
if(s[i]=='g'||s[i]=='h'||s[i]=='i') ss+='4';
if(s[i]=='j'||s[i]=='k'||s[i]=='l') ss+='5';
if(s[i]=='m'||s[i]=='n'||s[i]=='o') ss+='6';
if(s[i]=='p'||s[i]=='q'||s[i]=='r'||s[i]=='s') ss+='7';
if(s[i]=='t'||s[i]=='u'||s[i]=='v') ss+='8';
if(s[i]=='w'||s[i]=='x'||s[i]=='y'||s[i]=='z') ss+='9';
}
mp1[ss]=s;//映射关系
mp2[ss]++;//数量
}
cin>>m;
getchar();
getchar();
// getchar();
// getchar();
for(int i=1;i<=m;i++)
{
int flag=1;
ll ans=1;
ve.clear();
getline(cin,s);
// cout<<s<<endl;
stringstream ss(s);
while(ss>>s)
{
if(mp1.find(s)==mp1.end())//出现译码无对应单词
{
flag=3;
break;
}
else
{
if(mp2[s]!=1)//一个译码对应多个单词
{
ans*=mp2[s];
// cout<<mp2[s]<<endl;
flag=2;
}
}
ve.push_back(mp1[s]);
}
if(flag==1)//第一种情况
{
printf("Message #%d: ",++cnt);
int len=ve.size();
for(int i=0;i<len;i++)
{
if(i!=len-1) cout<<ve[i]<<" ";
else cout<<ve[i]<<endl;
}
cout<<endl;
}
else
if(flag==2)//第二种情况
{
printf("Message #%d: there are %lld possible messages\n\n",++cnt,ans);
}
else//最后一种情况
{
printf("Message #%d: not a valid text\n\n",++cnt);
}
}
}
C . Lawn Maintenance(计算几何)
大意
就是计算几何求多边形面积的板子题 ,复习一下板子
主要思路是根据三角剖分求出每一条边和原点构成的三角形的面积,然后简单相加;
根据矢量叉乘的几何意义 矢量A与矢量B的矢量积(叉积)是一个矢量,其模等于由A和B作成的平行四边形的面积,求出叉积除二就是三角形面积;所有三角形的有向面积相加就是总面积。
det 行列式求叉积
double area(int n)
{
double ans1=0;
for(int i=2;i<=n;i++) ans1+=(double)det(a[i],a[i-1])/2.0;//行列式求差积
ans1+=(double)det(a[1],a[n])/2.0;//
if(ans1>0.0) return ans1;
else return -ans1;//取正数
}
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct Point{
int x,y;
}a[11];
double ans;
int n,m,t;
int cnt;
double area(int n)
{
double ans1=0;
for(int i=2;i<=n;i++) ans1+=(double)(a[i].x*a[i-1].y-a[i].y*a[i-1].x)/2.0;
ans1+=(double)(a[1].x*a[n].y-a[1].y*a[n].x)/2.0;
if(ans1>0.0) return ans1;
else return -ans1;
}
int main()
{
while(cin>>t&&t)
{
ans=0.0;
for(int i=1;i<=t;i++)
{
cin>>a[i].x>>a[i].y;
}
ans+=area(t);
cin>>m;
for(int i=1;i<=m;i++)
{
cin>>a[i].x>>a[i].y;
}
ans-=area(m);
cin>>n;
while(n--)
{
cin>>m;
for(int i=1;i<=m;i++)
{
cin>>a[i].x>>a[i].y;
}
ans-=area(m);
}
printf("Lawn #%d: buy ",++cnt);
int anss=ceil(ans);//注意浮点数到整数的转换
if(anss%1000==0) cout<<ans/1000;
else cout<<anss/1000+1;
cout<<" bag(s)\n\n";
}
}
E . Waterford Wackiness(模拟)
题意:
n辆车过十字路口,给出 n 辆车的方向 , 距同方向前辆车的时间,和编号,打印出所有车辆经过路口的顺序;
思路:
以 0 时刻为参照 , 算出所有车经过路口的相对时间,排序即可
#include<bits/stdc++.h>
using namespace std;
struct node{
int id;
int sum;
}a[1001];
char c;
int sumn,sums,sume,sumw;
int n,t;
int cnt;
bool cmp(node a,node b)
{
return a.sum<b.sum;
}
int main()
{
cin>>t;
while(t--)
{
sumn=sums=sume=sumw=0;
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a[i].id>>c>>a[i].sum;
if(c=='E') sume+=a[i].sum,a[i].sum=sume;
if(c=='W') sumw+=a[i].sum,a[i].sum=sumw;
if(c=='N') sumn+=a[i].sum,a[i].sum=sumn;
if(c=='S') sums+=a[i].sum,a[i].sum=sums;
}
sort(a+1,a+1+n,cmp);
cout<<"Data set #"<<++cnt<<":"<<endl;
for(int i=1;i<=n;i++)
{
cout<<"Car #"<<a[i].id<<endl;
}
cout<<endl;
}
}
附上参考的博客
求多边形面积
边栏推荐
- Request (request object) and response (response object)
- Excellent PM must experience these three levels of transformation!
- EditorUtility.SetDirty在Untiy中的作用以及应用
- ByteDance program yuan teaches you how to brush algorithm questions: I'm not afraid of the interviewer tearing the code
- idea一键导包
- Programmers' position in the Internet industry | daily anecdotes
- Flink kakfa data read and write to Hudi
- nacos-高可用seata之TC搭建(02)
- Huawei equipment is configured with OSPF and BFD linkage
- Vite configures the development environment and production environment
猜你喜欢
Review of double pointer problems
F12 solve the problem that web pages cannot be copied
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
Lepton 无损压缩原理及性能分析
In 2022, we must enter the big factory as soon as possible
[mathematical modeling] differential equation -- sustainable development of fishing industry
用StopWatch 统计代码耗时
Orm-f & Q object
Nacos - TC Construction of High available seata (02)
Introduction of several RS485 isolated communication schemes
随机推荐
[mathematical modeling] differential equation -- sustainable development of fishing industry
麦斯克电子IPO被终止:曾拟募资8亿 河南资产是股东
SQL injection vulnerability (MSSQL injection)
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
Request (request object) and response (response object)
Extension of graph theory
Bill Gates posted his 18-year-old resume and expected an annual salary of $12000 48 years ago
Select knowledge points of structure
Postman assertion
[lgr-109] Luogu may race II & windy round 6
Review of double pointer problems
[buuctf.reverse] 159_ [watevrCTF 2019]Watshell
Crazy God said redis notes
Summary of three log knowledge points of MySQL
Flink kakfa data read and write to Hudi
麥斯克電子IPO被終止:曾擬募資8億 河南資產是股東
Codeforces Round #804 (Div. 2)
RTP gb28181 document testing tool
Nestjs配置文件上传, 配置中间件以及管道的使用
Summary of redis AOF and RDB knowledge points