题意:
求最小数的最小距离。wa了好几发,菜的抠脚。。。间隔结构体记录位置就好了
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdio>
#define ll long long
#define maxn 100005
#define inf 1000000001
using namespace std;
struct Node{
int x;
int pos;
}node[maxn];
int main(){
int n;
while(cin>>n){
int minn=inf;
for(int i=1;i<=n;i++)
{
cin>>node[i].x;
node[i].pos=i;
if(minn>node[i].x)
minn=node[i].x;
}
int tem=0;
int mm=inf;
int p;
bool flag=false;
for(int i=1;i<=n;i++){
if(node[i].x==minn&&flag==false){
tem=node[i].pos;
flag=true;
}
else if(node[i].x==minn&&flag==true){
p=node[i].pos-tem;
mm=min(mm,p);
tem=node[i].pos;
}
}
cout<<mm<<endl;
}
return 0;
}
题意:
有两块蛋糕,分别被分成a条,b条,有三条规定:
(1)每条蛋糕必须分到一个盘子(一开始忘了这一点,wa了一发)
(2)每个盘子至少包含一条蛋糕
(3)一个盘子里不能包含有两个蛋糕
求某个分法使得分到的最小的蛋糕最大。
思路:
因为一个盘子不能有两种蛋糕,其实就是将有多少个盘子分解开来就好,然后求最小里面的最大
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdio>
#define ll long long
#define maxn 100005
#define inf 1000000001
using namespace std;
int n,a,b;
int main(){
while(cin>>n>>a>>b){
if(n==(a+b)){
cout<<"1"<<endl;
continue;
}
int maxx=-1;
int m,mm;
int tem;
for(int i=1;i<=n-1;i++){
/*if(i==0){
mm=b/n;
maxx=max(maxx,mm);
}
else if(i==n){
m=a/n;
maxx=max(maxx,m);
}
else{ */
m=a/i;
mm=b/(n-i);
tem=min(m,mm);
maxx=max(tem,maxx);
}
cout<<maxx<<endl;
}
return 0;
}
有三个未知数,每个数的周期为 a,b,c.。问能否确定s个数能表示所有数
思路:
比赛时没做出来,其实就是找出可能的情况就行。但是确实不好找
代码:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#define ll long long
#define maxn 10005
#define inf 1000000001
using namespace std;
int main() {
vector<int> arr(3);
for (int i = 0; i < 3; ++i)
cin >> arr[i];
sort(arr.begin(), arr.end());
if (arr[0] == 1) {
cout << "YES";
}
else if (arr[0] == 2){
if (arr[1] == 2||(arr[1] == 4 &&arr[2] == 4))
cout << "YES";
else
cout << "NO";
}
else if (arr[0] == 3) {
if (arr[1] == 3 && arr[2] == 3)
cout << "YES";
else
cout << "NO";
}
else {
cout << "NO";
}
return 0;
}