zoukankan      html  css  js  c++  java
  • 2020-03-14 解题报告

    F. Floor Plan

    You are an architect and you have just been appointed to build a new swimming hall. The organisation behind these plans has acquired funding for a swimming pool and surrounding building as large as they want, but unfortunately they could not find anyone willing to pay for the floor surrounding the pool. They decided to pay for the floor tiles out of their own pocket. Because this has already cost them an arm and a leg, they want you to use all the floor tiles in your proposed plan. 

    Being an architect, you care for aesthetics. You see it as absolutely vital that both the swimming pool and the surrounding building are perfect squares. This raises an interesting problem: how can you make sure that the square shapes are guaranteed, while still using all the floor tiles the organisation bought? 

    Given the number of tiles n, find the length of the side of the building m and the length of the side of the pool k such that n = m^2 − k^2, or print "impossible" if no suitable m and k exist. 

    INPUT:

    • One line containing a single integer 1 ≤ n ≤ 10^9.

    Output:

     Print two non-negative integers m, k such that n = m^2−k^2, or print impossible if no such integers exist. If there are multiple valid solutions, you may output any one of them.

    NOTE:

    For all case,0<=m,k<10^18

    本题答案不唯一,符合要求的答案均正确

     

    题目大意是找出符合条件的 m,k 使得 n = m^2−k^2 

    思路是大佬队友想出来的

     

     1 #include <iostream>
     2 using namespace std;
     3 int main(){
     4     int m,k;
     5     int n;
     6     cin>>n;
     7     if(n%4==0){
     8         cout<<(n/2+2)/2<<" "<<(n/2-2)/2<<endl;
     9     }
    10     else if(n%2==0){
    11         cout<<"impossible"<<endl;
    12     }
    13     else{
    14         cout<<n/2+1<<" "<<n/2<<endl;
    15     }
    16     return 0;
    17 }

     I. Inquiry I

    The Bureau for Artificial Problems in Competitions wants you to solve the following problem: Given n positive integers a1, . . . , an, what is the maximal value of 

    forma.jpg

    Input: 

    • A single line containing an integer 2 ≤ n ≤ 10^6. 

    • Then follow n lines, the ith of which contains the integer 1 ≤ ai ≤ 100.

    Output:

     Output the maximal value of the given expression.

    看了网上的答案,思路是先加全部的数,再判断出最大的答案

    自己写了一遍

    注意数据范围,res 用long long

     1 #include <iostream>
     2 #include <cmath>
     3 #define ll long long
     4 using namespace std;
     5 
     6 int a[1000000];
     7 
     8 int main(){
     9     int n;
    10     cin>>n;
    11     ll sum1=0,sum2=0;
    12     for(int i=0;i<n;i++){
    13         cin>>a[i];
    14         sum2+=a[i];
    15     }
    16     ll res=sum1*sum2;
    17     for(int i=0;i<n;i++){
    18         sum1+=pow(a[i],2);
    19         sum2-=a[i];
    20         res=max(res,sum1*sum2);
    21     }
    22     cout<<res<<endl;
    23     return 0;
    24 }
  • 相关阅读:
    【ASP.NET】服务器控件大演练与实例分析
    【利用存储过程和三层架构完成新闻发布】
    【软件工程】web规格开发全过程
    【数据库】如何解决数据库附加失败问题
    【框架设计】异常
    【数据库】SqlCommand的几个易忽视的执行操作
    【ASP.NET】asp.net 页面调用服务端对象值
    【c#迭代器】
    【框架设计】CLR寄宿和应用程序域
    【ASP.NET】演绎GridView基本操作事件
  • 原文地址:https://www.cnblogs.com/-gcq/p/12521390.html
Copyright © 2011-2022 走看看