今天刚刚回学校
有些无聊...
昂神推荐一个练习...
18:45开始...
去做了一下...
还有两道题..
一个是nim博弈不会做..
还有一个是字符串dp吧看样子...也不太会..或者说木有耐心做...
好饿..
去吃点东西..
明天不拖小明后腿好好训练..
#include<iostream>
#include<algorithm>
#define INF 0x3f3f3f3f
using namespace std;
struct node
{
double left;
double right;
}house[10005];
bool cmp(const node &x,const node &y)
{
return x.left<y.left;
}
int main()
{
int n;
double t;
while(cin>>n>>t)
{
for(int i=1;i<=n;i++)
{
double x,a;
cin>>x>>a;
house[i].left=x-a/2;
house[i].right=x+a/2;
}
house[0].left=house[0].right=-INF;
sort(house+1,house+n+1,cmp);
int ans=0;
for(int i=1;i<=n;i++)
{
if(house[i].left-house[i-1].right>t)
{
ans+=2;
}
else if(house[i].left-house[i-1].right==t)
{
ans+=1;
}
}
cout<<ans<<endl;
}
return 0;
}
/*
容斥原理
画个图就清楚了
*/
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int T;
cin>>T;
while(T--)
{
long long n,m,x1,y1,x2,y2;
long long minx,miny,maxx,maxy,up,left,right,down;
long long lenleft,lenright,lenup,lendown,deltax=0,deltay=0;
long long ans=0;
cin>>n>>m>>x1>>y1>>x2>>y2;
minx=min(x1,x2);
miny=min(y1,y2);//左上点
maxx=max(x1,x2);
maxy=max(y1,y2);//右下点
up=minx-1;//距四边距离
left=miny-1;
down=n-maxx;
right=m-maxy;
lendown=minx+down;//分别覆盖举行长宽
lenleft=miny+right;
lenup=maxx-up;
lenright=maxy-left;
if(lendown>=lenup)//相交部分
{
deltax=lendown-lenup+1;
}
if(lenleft>=lenright)
{
deltay=lenleft-lenright+1;
}
ans=lendown*lenleft+(n-lenup+1)*(m-lenright+1);
if(deltax>0&&deltay>0)//容斥
{
ans-=deltax*deltay;
}
cout<<n*m-ans<<endl;
}
return 0;
}
Description
Nick is interested in prime numbers. Once he read about Goldbach problem. It states that every even integer greater than 2 can be expressed as the sum of two primes. That got Nick's attention and he decided to invent a problem of his own and call it Noldbach problem. Since Nick is interested only in prime numbers, Noldbach problem states that at least k prime numbers from 2 to n inclusively can be expressed as the sum of three integer numbers: two neighboring prime numbers and 1. For example, 19 = 7 + 11 + 1, or 13 = 5 + 7 + 1.
Two prime numbers are called neighboring if there are no other prime numbers between them.
You are to help Nick, and find out if he is right or wrong.
Input
The first line of the input contains two integers n (2 ≤ n ≤ 1000) and k (0 ≤ k ≤ 1000).
Output
Sample Input
27 2
YES
45 7
NO
Hint
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
using namespace std;
int prime[1005];
int a[1005];
void init()
{
memset(prime,1,sizeof(prime));
prime[0]=0;
prime[1]=0;
int k=0;
for(int i=2;i<=1000;i++)
{
if(prime[i])
{
a[k++]=i;
for(int j=i+i;j<=1000;j+=i)
{
prime[j]=0;
}
}
}
}
int main()
{
init();
int n,k;
while(cin>>n>>k)
{
int ans=0;
for(int i=1;a[i]<=n;i++)
{
int temp=a[i]+a[i-1]+1;
if(prime[temp]&&temp<=n)
{
ans++;
}
}
if(ans<k)
{
cout<<"NO"<<endl;
}
else
{
cout<<"YES"<<endl;
}
}
return 0;
}
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#define INF 0x3f3f3f3f
using namespace std;
int main()
{
int n;
cin>>n;
int cost[1005];
memset(cost,INF,sizeof(cost));
for(int i=1;i<=n;i++)
{
int temp;
cin>>temp;
}
int m;
cin>>m;
while(m--)
{
int a,b,c;
cin>>a>>b>>c;
cost[b]=min(cost[b],c);
}
int ans=0;
int flag=1;
int first=1;
for(int i=1;i<=n;i++)
{
// cout<<cost[i]<<endl;
if(cost[i]==INF&&first)
{
first=0;
ans-=INF;
}
else if(cost[i]==INF)
{
flag=0;
}
ans+=cost[i];
}
if(flag)
{
cout<<ans<<endl;
}
else
{
cout<<"-1"<<endl;
}
return 0;
}
加油啊~
好好训练一个月就可以回去开黑十天了...