当前位置:网站首页>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;
}
}
附上参考的博客
求多边形面积
边栏推荐
- Raspberry pie 3.5-inch white screen display connection
- 2021 RoboCom 世界机器人开发者大赛-本科组(复赛)
- Summary of redis AOF and RDB knowledge points
- Knowledge points of circular structure
- Nestjs配置文件上传, 配置中间件以及管道的使用
- Imperial cms7.5 imitation "D9 download station" software application download website source code
- Nacos TC setup of highly available Seata (02)
- EditorUtility. The role and application of setdirty in untiy
- idea一键导包
- Three.js学习-光照和阴影(了解向)
猜你喜欢

Excel转换为Lua的配置文件

Hyperledger Fabric2. Some basic concepts of X (1)

nacos-高可用seata之TC搭建(02)

Compilation et connexion de shader dans games202 - webgl (comprendre la direction)

Postman前置脚本-全局变量和环境变量

Principle and performance analysis of lepton lossless compression

Steady, 35K, byte business data analysis post
![[untitled]](/img/7e/d0724193f2f2c8681a68bda9e08289.jpg)
[untitled]

Class inheritance in yyds dry inventory C

Golang -- TCP implements concurrency (server and client)
随机推荐
The underlying structure of five data types in redis
Application of Flody
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
Excel转换为Lua的配置文件
Microblogging hot search stock selection strategy
Some common skills on unity inspector are generally used for editor extension or others
Principle and performance analysis of lepton lossless compression
The web project imported the MySQL driver jar package but failed to load it into the driver
Postman管理测试用例
Mysql高级篇学习总结9:创建索引、删除索引、降序索引、隐藏索引
GAMES202-WebGL中shader的编译和连接(了解向)
麥斯克電子IPO被終止:曾擬募資8億 河南資產是股東
The kernel determines whether peripherals are attached to the I2C address
nacos-高可用seata之TC搭建(02)
从0到1建设智能灰度数据体系:以vivo游戏中心为例
Flink kakfa data read and write to Hudi
pix2pix:使用条件对抗网络的图像到图像转换
Review of double pointer problems
Weng Kai C language third week 3.1 punch in
February 12 relativelayout