CSU 1392: Number Trick 1393: Robert Hood

1392: Number Trick


#include <cstdio>
typedef long long ll;
using namespace std;
 
int power[10],a[10010],ans=0;
float x,tmpx;//不知道为什么用double会wa
ll f1,f2;
 
int digit(ll tmp)
{
  int tot=0;
  while(tmp) tot++,tmp/=10;
  return tot;
}
 
int head(ll tmp)
{
  for (; tmp>=10; tmp/=10);
  return tmp;
}
 
int main()
{
  power[0]=1;
  for (int i=1; i<=9; i++) power[i]=power[i-1]*10;
  scanf("%f",&x);
  if (x>=10)
  {
    printf("No solution\n");
    return 0;
  }
  for (int i=1; i<=8; i++)//枚举总共几个数位
    for (int j=1; j<=9; j++)//枚举开头数字
    {
      tmpx=100000-10000*x;
      f1=(int)tmpx;
      f2=(ll)10000*(power[i]-1)*j;
      if (f2%f1!=0) continue;
      f2/=f1;
      if (digit(f2)==i && head(f2)==j) a[++ans]=f2;
    }
  if (ans==0) printf("No solution\n");
    else for (int i=1; i<=ans; i++) printf("%d\n",a[i]);
  return 0;
}
/**********************************************************************
	Problem: 1392
	User: 3901140225
	Language: C++
	Result: AC
	Time:0 ms
	Memory:1160 kb
**********************************************************************/

1393: Robert Hood


#include<stdio.h>
#include<math.h>
#include<string.h>
#include<algorithm>
using namespace std;

const int maxn = 100000+10;
int n,m;

struct Point{
    double x,y;
    Point(){};
    Point(double _x, double _y)
    {
        x = _x;
        y = _y;
    }

    Point operator - (const Point & B) const
    {
        return Point(x-B.x, y-B.y);
    }
}p[maxn], ch[maxn];

bool cmp(Point p1, Point p2)
{
    if(p1.x == p2.x) return p1.y < p2.y;
    return p1.x < p2.x;
}

int squarDist(Point A, Point B) /**距离的平方*/
{
    return (A.x-B.x)*(A.x-B.x) + (A.y-B.y)*(A.y-B.y);
}

double Cross(Point A, Point B) /**叉积*/
{
    return A.x*B.y-A.y*B.x;
}

void ConvexHull() /** 基于水平的Andrew算法求凸包 */
{
    sort(p,p+n,cmp); /**先按照 x 从小到大排序, 再按照 y 从小到大排序*/
    m = 0;

    for(int i = 0; i < n; i++) /** 从前往后找 */
    {
        while(m > 1 && Cross(ch[m-1]-ch[m-2], p[i]-ch[m-2]) <= 0) m--;
        ch[m++] = p[i];
    }
    int k = m;
    for(int i = n-2; i >= 0; i--) /**从后往前找, 形成完整的封闭背包*/
    {
        while(m > k && Cross(ch[m-1]-ch[m-2], p[i]-ch[m-2]) <= 0) m--;
        ch[m++] = p[i];
    }
    if(n > 1) m--;
}

int rotating_calipers() /**旋转卡壳模板*/
{
    int q = 1;
    int ans = 0;
    ch[m] = ch[0]; /**凸包边界处理*/
    for(int i = 0; i < m; i++) /**依次用叉积找出凸包每一条边对应的最高点*/
    {
        while(Cross(ch[i+1]-ch[i], ch[q+1]-ch[i]) > Cross(ch[i+1]-ch[i], ch[q]-ch[i]))
            q = (q+1)%m;
        ans = max(ans, max(squarDist(ch[i], ch[q]), squarDist(ch[i+1], ch[q+1])));
    }
    return ans;
}

int main()
{
    while(scanf("%d", &n) != EOF)
    {
        if(n == 0) break;
        for(int i = 0; i < n; i++)
            scanf("%lf%lf", &p[i].x, &p[i].y);

        ConvexHull();

        printf("%.8lf\n", sqrt(rotating_calipers()));
    }
    return 0;
}
/**********************************************************************
	Problem: 1393
	User: 3901140225
	Language: C++
	Result: AC
	Time:92 ms
	Memory:4260 kb
**********************************************************************/


猜你喜欢

转载自blog.csdn.net/nameofcsdn/article/details/80235550