I. Neighborhood Search
題意: 第一行是一個集合,第二行與第三行分別輸入 A , r A,r A,r輸出集合中 A ? r , A + r A-r,A+r A?r,A+r的值,
#include <bits/stdc++.h>
using namespace std;
using ll = long long ;
int main()
{
ios::sync_with_stdio(false);
int x;
deque<int>q;
vector<int>a;
while(cin>>x){
q.push_back(x);
while(q.size()>2){
a.push_back(q.front());
q.pop_front();
}
}
sort(a.begin(),a.end());
int l=lower_bound(a.begin(),a.end(),q[0]-q[1])-a.begin(),r=upper_bound(a.begin(),a.end(),q[0]+q[1])-a.begin()-1;
if(l==a.size()){
cout<<"\n";
}else{
for(int i=r;i>=l;i--)
cout<<a[i]<<' ';
}
}
F. Land Overseer
計算幾何(簽到)
#include <bits/stdc++.h>
using namespace std;
using ll = long long ;
int main()
{
int t;
scanf("%d",&t);
for(int i=1;i<=t;i++){
double a,b,r;
scanf("%lf%lf%lf",&a,&b,&r);
if(r>=b){
printf("Case #%d: %.2lf\n",i,2*a-r);
}else{
double ans=sqrt(a*a+pow(b-r,2))*2.0-r;
printf("Case #%d: %.2lf\n",i,ans);
}
}
}
H.Mesh Analysis
模擬
#include <bits/stdc++.h>
using namespace std;
using ll = long long ;
map<int,set<int>>mp1,mp2;
int main()
{
int n,m;
cin>>n>>m;getchar();
string s;
while(n--)getline(cin,s);
while(m--){
int i,u,a,b,c;
cin>>i>>u;
if(u==203){
cin>>a>>b>>c;
mp1[a].insert(i);
mp1[b].insert(i);
mp1[c].insert(i);
mp2[a].insert(b);
mp2[a].insert(c);
mp2[b].insert(a);
mp2[b].insert(c);
mp2[c].insert(a);
mp2[c].insert(b);
}
else{
cin>>a>>b;
mp1[a].insert(i);
mp1[b].insert(i);
mp2[a].insert(b);
mp2[b].insert(a);
}
}
int q;
cin>>q;
while(q--){
int x;cin>>x;
cout<<x<<"\n[";
bool f=0;
for(auto &t:mp2[x]){
if(f)cout<<',';
cout<<t;f=1;
}
cout<<"]\n[";
f=0;
for(auto &t:mp1[x]){
if(f)cout<<',';
cout<<t;f=1;
}
cout<<"]\n";
}
}
k.Segment Routing
閱讀理解輸入前 n n n行表示第 i i i行到 x x x的有向邊,前 m m m行表示從第 x 1 x_1 x1?個數往后走 x 2 . . . x_2... x2?...個數最后走到哪里,走不到回傳 P a c k e t L o s s Packet Loss PacketLoss,
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define re register
#define ll long long int
using namespace std;
const int N = 1e5 + 10;
vector<ll> road[N];
void test(ll n)
{
for (ll i = 0; i < n; i++)
{
for (ll j = 0; j < road[i].size(); j++)
cout << road[i][j] << " ";
cout << "\n";
}
}
signed main()
{
ll t = 1; cin >> t;
for (ll k = 1; k <= t; k++)
{
ll n, m; cin >> n >> m;
ll ways, way;
for (ll i = 1; i <= n; i++)
{
road[i].clear();
cin >> ways;
for (int j = 1; j <= ways; j++)
{
cin >> way;
road[i].push_back(way);
}
}
//test(n);
cout << "Case #" << k << ": \n";
for (ll i = 1; i <= m; i++)
{
ll start = 0;
ll times = 0;
bool exist = 1;
cin >> start >> times;
ll cur = start; ll to;
for (ll j = 1; j <= times; j++)
{
cin >> to;
if (to > road[cur].size() || !to) exist = 0;
if (!exist) continue;
cur = road[cur][to - 1];
}
if (!exist) cout << "Packet Loss\n";
else cout << cur << "\n";
}
}
return 0;
}
A.Busiest Computing Nodes
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/301956.html
標籤:其他
上一篇:學習記錄:軟體測驗的最常見的誤解
