A.圆周率日挑战
补
B.正则表达式
签到题
只需要判断a,b,c,d范围是不是在[0,255]
输入方法看下面代码
#include<iostream>
#include<algorithm>
#define int long long
using namespace std;
signed main()
{
int n;
cin>>n;
int ss=0;
while(n--)
{
int a,b,c,d;
scanf("%lld.%lld.%lld.%lld",&a,&b,&c,&d);
if(a<0||b<0||c<0||d<0||a>255||b>255||c>255||d>255)
continue;
else
ss++;
}
cout<<ss;
}
C.Circle
圆的个数n | 0 | 1 | 2 | 3 | 4 | 5 |
区域的个数 | 1 | 2 | 4 | 8 | 14 | 2 |
找规律: f(n)=f(n-1)+2*(n-1)
f(1)=2
f(2)=f(1)+2*(2-1)
f(3)=f(2)+2*(3-1)
所以f(n)=2+2*(1+2+3+4+....+(n-1))=2+n*(n-1)=n*n-n+2
#include<iostream>
#include<algorithm>
#define int long long
using namespace std;
int n;
signed main()
{
int t;
cin>>t;
while(t--)
{
cin>>n;
if(n==0)
cout<<"1 ";
else
cout<<n*n-n+2<<' ';
}
}
D.开心消消乐(Right Version)
没看懂
#include<iostream>
using namespace std;
int main()
{
int n;
cin>>n;
int t=-1;
int ans=0;
for(int i=0;i<n;i++)
{
int x;
cin>>x;
if(x!=t)
{
t=x;
if(x!=0)
ans++;
}
}
cout<<ans;
}
E.区间
补
F.累加器
写一个前缀和,让求x~x+y,就求1~x+y - 1~x
两种方法:(1).正常求改变的1。(2).bitset异或就1。【推荐第二种】
#include<iostream>
#include<algorithm>
#include<vector>
#define int long long
using namespace std;
const int N = 2e6;
int a[N];
void init()
{
for(int i=1;i<=N;i++)
{
int x=i-1;
int sum=1;
while(x%2)
{
sum++;
x/=2;
}
a[i]=a[i-1]+sum;
}
}
signed main()
{
int t;
cin>>t;
init();
while(t--)
{
int x,y;
cin>>x>>y;
cout<<a[x+y]-a[x]<<endl;
}
}
#include<iostream>
#include<bitset>
#define int long long
using namespace std;
const int N = 2e6+7;
bitset<30> b;
int a[N];
void init()
{
for(int i=1;i<=N;i++)
{
b=(i-1)^i;
a[i]=a[i-1]+b.count();
}
}
signed main()
{
int t;
cin>>t;
init();
while(t--)
{
int x,y;
cin>>x>>y;
cout<<a[x+y]-a[x]<<endl;
}
}
G.求值
补
H.魔法
补
I.游戏
补
J.keillempkill学姐の卷积
暴力
#include<iostream>
#include<algorithm>
#define int long long
using namespace std;
int a[30][30],b[30][30];
signed main()
{
int n,m;
cin>>n>>m;
//卷积核
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
cin>>a[i][j];
//矩阵
for(int i=1;i<=m;i++)
for(int j=1;j<=m;j++)
cin>>b[i][j];
//答案
for(int i=1;i<=m-n+1;i++)
{
for(int j=1;j<=m-n+1;j++)
{
//每一个值
int ans=0;
for(int x=i,x1=1;x<=n+i;x++,x1++)
{
for(int y=j,y1=1;y<=n+j;y++,y1++)
{
ans+=b[x][y]*a[x1][y1];
}
}
cout<<ans<<' ';
}
cout<<endl;
}
}
K.暴食之史莱姆
补
L.SSH
用map函数存储
#include<iostream>
#include<map>
#include<set>
using namespace std;
map<string,string>my;//密钥对
map<string,set<string>>hosts;//主机信息
int main()
{
int m,n,q;
cin>>m>>n>>q;
//密钥对map
while(m--)
{
string pub,pri;
cin>>pub>>pri;
my[pri]=pub;
}
//主机信息
while(n--)
{
string ipv4;//地址
int k;//用户数量
cin>>ipv4>>k;
while(k--)
{
string name;//用户名
int t;//公钥个数
cin>>name>>t;
string key;
key=ipv4+" "+name;//地址加用户名
while(t--)
{
string pub;//公钥
cin>>pub;
hosts[key].insert(pub);
}
}
}
//查询
while(q--)
{
string user,ip,pri;//用户名,地址,私钥
cin>>user>>ip>>pri;
string pub=my[pri];//通过私钥找公钥
string key=ip+" "+user;
if(hosts[key].count(pub))
cout<<"Yes\n";
else
cout<<"No\n";
}
}
M. 推箱子
补
总结
这也不萌新啊(啊呜呜呜呜~)