Basic math problems in the introductory classic of algorithmic competition

Source: Internet
Author: User
Tags cmath

uva575: There's nothing to say about this problem.

1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cmath>5#include <algorithm>6#include <string>7#include <cctype>8#include <vector>9#include <map>Ten using namespacestd; One Const intmaxn= +; A strings; - intA[MAXN]; - intMain () the { -     Long Longsum; -      while(cin>>s) -     { +         if(s[0]=='0') -          Break; +sum=0; AMemset (A,0,sizeof(a)); at          for(intI=0; I<s.length (); i++) -A[s.length ()-i-1]=s[i]-'0'; -          for(intI=0; I<s.length (); i++) -sum+=a[i]* (POW (2, i+1)-1); -cout<<sum<<Endl; -     } in     return 0; -}
View Code


UVA10110:

This topic considers the factor of the last number, if is even is closed, odd is open, it is obvious that the general number is even, only one case, is the total square number of time is odd, so judge

SQRT (n) *sqrt (n) is equal to n

1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cmath>5 using namespacestd;6 Long LongN;7 voidjudge ()8 {9     Long Longb=sqrt (n);Ten     if(b*b==N) Onecout<<"Yes"<<Endl; A     Else -cout<<"No"<<Endl; - } the intMain () - { -      while(cin>>N) -     { +         if(n==0) -              Break; + judge (); A     } at     return 0; -}
View Code

Basic math problems in the introductory classic of algorithmic competition

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.