当前位置:网站首页>UCF (summer team competition II)
UCF (summer team competition II)
2022-07-06 05:14:00 【. Ashy.】
List of articles
A . T9 Craziness( Selection structure )
Carelessness :
Give the letter corresponding to each number , Give the existing dictionary string , Give multiple groups of decoding , If each decoding in a group has only one corresponding word , Then translate the sentence , If there is decoding that cannot be translated, it will not be translated , If there is decoding corresponding to multiple words, the total number of cases will be output ;
Ideas
First decode the dictionary string , Use one map Keep correspondence , With another map Write down the The number of words corresponding to each decoding , Then judge ;
#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;// The mapping relationship
mp2[ss]++;// Number
}
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())// There is no corresponding word for decoding
{
flag=3;
break;
}
else
{
if(mp2[s]!=1)// One decoding corresponds to multiple words
{
ans*=mp2[s];
// cout<<mp2[s]<<endl;
flag=2;
}
}
ve.push_back(mp1[s]);
}
if(flag==1)// Case one
{
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)// The second case
{
printf("Message #%d: there are %lld possible messages\n\n",++cnt,ans);
}
else// Last case
{
printf("Message #%d: not a valid text\n\n",++cnt);
}
}
}
C . Lawn Maintenance( Computational geometry )
Carelessness
It is the board problem of calculating the area of polygons in geometry , Review the board
The main idea is to calculate the area of the triangle formed by each edge and the origin according to triangulation , Then simply add ;
According to the geometric meaning of vector cross multiplication vector A And vector B Vector product of ( Cross product ) It's a vector , Its modulus is equal to A and B The area of the parallelogram made , Finding the cross product divided by two is the area of the triangle ; The sum of the directed areas of all triangles is the total area .
det Find the cross product of determinant
double area(int n)
{
double ans1=0;
for(int i=2;i<=n;i++) ans1+=(double)det(a[i],a[i-1])/2.0;// Determinant to find the difference product
ans1+=(double)det(a[1],a[n])/2.0;//
if(ans1>0.0) return ans1;
else return -ans1;// Take positive number
}
#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);// Notice the conversion from floating point number to integer
if(anss%1000==0) cout<<ans/1000;
else cout<<anss/1000+1;
cout<<" bag(s)\n\n";
}
}
E . Waterford Wackiness( simulation )
The question :
n A car passed the intersection , give n Direction of vehicle , Time from the previous car in the same direction , And number , Print out the sequence of all vehicles passing the intersection ;
Ideas :
With 0 Time as reference , Calculate the relative time of all vehicles passing the intersection , Sorting can be
#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;
}
}
Attached is a reference blog
Find the area of a polygon
边栏推荐
- Fuzzy -- basic application method of AFL
- [leetcode16] the sum of the nearest three numbers (double pointer)
- Realize a binary read-write address book
- Yolov5 tensorrt acceleration
- Driver development - hellowdm driver
- Oracle deletes duplicate data, leaving only one
- Cuda11.1 online installation
- Compilation and connection of shader in games202 webgl (learn from)
- Idea one key guide package
- February 12 relativelayout
猜你喜欢
Flody的应用
The underlying structure of five data types in redis
Microblogging hot search stock selection strategy
Golang -- TCP implements concurrency (server and client)
[leetcode16] the sum of the nearest three numbers (double pointer)
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
ByteDance program yuan teaches you how to brush algorithm questions: I'm not afraid of the interviewer tearing the code
图论的扩展
Configuration file converted from Excel to Lua
麦斯克电子IPO被终止:曾拟募资8亿 河南资产是股东
随机推荐
Finance online homework
Why does MySQL need two-phase commit
Three methods of Oracle two table Association update
[untitled]
[noip2008 improvement group] stupid monkey
Leetcode dynamic planning day 16
Postman前置脚本-全局变量和环境变量
Realize a binary read-write address book
acwing周赛58
【OSPF 和 ISIS 在多路访问网络中对掩码的要求】
關於Unity Inspector上的一些常用技巧,一般用於編輯器擴展或者其他
[buuctf.reverse] 159_[watevrCTF 2019]Watshell
树莓派3.5寸屏幕白屏显示连接
Oracle query table index, unique constraint, field
Three.js学习-光照和阴影(了解向)
C# AES对字符串进行加密
Hometown 20 years later (primary school exercises)
Yyds dry inventory SSH Remote Connection introduction
Driver development - hellowdm driver
驱动开发——HelloWDM驱动