B
#include<cstdio>
using namespace std;
int main()
{
int n;
scanf("%d",&n);int res=0;
while(n--)
{
int a,b,c,d;
bool x=false;
scanf("%d.%d.%d.%d",&a,&b,&c,&d);
if(a<0||a>255)
x=true;if(b<0||b>255)
x=true;if(c<0||c>255)
x=true;if(d<0||d>255)
x=true;
if(!x)
res++;
}
cout<<res;
return 0;
}
C
using namespace std;
using ll =long long ;
#define int long long
#define INF 0x3f3f3f3f
const int N=1e5+5;
const int mod=998244353;
ll ksm(ll a,ll b){ll ans=1;while(b){if(b&1){ans*=a;ans=ans%mod;}a=a*a;a%=mod;b>>=1;}return ans;}
ll gcd(ll a,ll b){ll t=a%b;while(t){a=b;b=t;t=a%b;}return b;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll get_inv(ll x){return ksm(x,mod-2);}
void solve()
{
int n;cin>>n;int t=2+n*(n-1);if(n==0)t=1;cout<<t<<' ';
}
signed main()
{
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int _;cin>>_;while(_--)
solve();
}
J
using namespace std;
int a[21][21],b[21][21],c[21][21];
int main()
{
int n,m;
cin>>n>>m;
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
cin>>a[i][j];
}
}
for(int i=0;i<m;i++)
{
for(int j=0;j<m;j++)
{
cin>>b[i][j];
}
}
int len=m-n+1;
int l=0;
int r=0;
int res=0;
for(int l=0;l<len;l++)
{
for(int r=0;r<len;r++)
{
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
res=res+a[i][j]*b[i+l][j+r];
}
}
c[l][r]=res;
cout<<res<<" ";
res=0;
}
cout<<endl;
}
}
F
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
while(n--)
{
long long x,y;
cin>>x>>y;
long long res=0;
long long t=1;
while(t<2*(x+y))
{
res=res+(y+x%t)/t;
t*=2;
}
cout<<res<<endl;
}
}
L
#include<bits/stdc++.h>
using namespace std;
struct sever
{
vector<string>id;
map<string,vector<string>> gy;
};
int main()
{
map<string,sever>a;
map<string,string> pp;
int m,n,q;
cin>>m>>n>>q;
for(int i=0;i<m;i++)
{
string pub,pri;
cin>>pub>>pri;
pp[pub]=pri;
}
for(int i=0;i<n;i++)
{
string ip;
int x;
cin>>ip>>x;
for(int j=0;j<x;j++)
{
string name;
cin>>name;
int num;
cin>>num;
a[ip].id.push_back(name);
for(int k=0;k<num;k++)
{
string ky;
cin>>ky;
a[ip].gy[name].push_back(ky);
}
}
}
for(int i=0;i<q;i++)
{
string name;
cin>>name;
string idx;
cin>>idx;
string my;
cin>>my;
bool ans=false;
for(auto t:a[idx].id)
{
if(t==name)
{
for(auto tt:a[idx].gy[name])
{
if(pp[tt]==my)
{
ans=true;
break;
}
}
}
}
if(ans)
cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
}
I
#include<bits/stdc++.h>
using namespace std;
const long long N = 1e6 + 10;
#define pll pair<long long,long long>
const long long INF = 0x3f3f3f3f;
long long e[N], ne[N], idx, w[N], h[N], k[N], dis[N], dist[N];
bool kk;
bool vis[N];
bool vist[N];
long long n, m, k1;
void add(long long a, long long b, long long c, long long d)
{
e[idx] = b;
ne[idx] = h[a];
w[idx] = c;
k[idx] = d;
h[a] = idx;
idx++;
}
void dij(long long ke)
{
priority_queue<pll, vector<pll>, greater<pll>> q;
q.push({ 0,1 });
dis[1] = 0;
while (q.size())
{
auto t = q.top();
q.pop();
long long x = t.second;
if (vis[x])
continue;
vis[x] = true;
for (long long i = h[x];i != -1;i = ne[i])
{
if (k[i] == 0)
continue;
long long tt = e[i];
if (dis[tt] > dis[x] + w[i])
{
dis[tt] = dis[x] + w[i];
q.push({ dis[tt],tt });
}
}
}
if (vis[ke])
{
q.push({ 0,ke });
dist[ke] = 0;
while (q.size())
{
auto t = q.top();
q.pop();
long long x = t.second;
if (vist[x])
continue;
vist[x] = true;
for (long long i = h[x];i != -1;i = ne[i])
{
long long tt = e[i];
if (dist[tt] > dist[x] + w[i])
{
dist[tt] = dist[x] + w[i];
q.push({ dist[tt],tt });
}
}
}
}
if (!vis[n] && !vist[n])
cout << -1;
else
{
if (dis[n] > dis[k1] + dist[n])
dis[n] = dis[k1] + dist[n];
cout << dis[n];
}
}
signed main()
{
cin >> n >> m >> k1;
memset(h, -1, sizeof h);
memset(dis, INF, sizeof dis);
memset(dist, INF, sizeof dist);
for (long long i = 0;i < m;i++)
{
long long x, y, a, b;
cin >> x >> y >> a >> b;
add(x, y, a, b);
add(y, x, a, b);
}
dij(k1);
return 0;
}