HDU 1337 && POJ 1218&& zju 1350 Method Summary

Source: Internet
Author: User

Topic Link http://acm.hdu.edu.cn/showproblem.php?pid=1337 Hangzhou Electric

http://poj.org/problem?id=1218 Tsinghua

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1350 Zhejiang

Originally thought that a small water problem is not worth summarizing, but found that there are many ways, good magic AH

Method One: The data is very small simulation is good

#include <iostream> #include <algorithm> #include <stdio.h> #include <string.h>using namespace Std;int A[110];int Main () {    int t, N;    scanf ("%d", &t);    while (t--)    {        memset (a, 0, sizeof (a));        scanf ("%d", &n);        for (int i=1, i<=n; i++)        {for            (int j=i; j<=n; j+=i)            {                a[j]=a[j]^1;            }        }        int ans=0;        for (int i=1; i<=n; i++)        {            if (a[i]==1)                ans++;        }        printf ("%d\n", ans);    }    return 0;}

Method Two: In fact, the prisoner can escape is a regular follow, the door has two forms, as long as the total number of prisoners to open and close is odd, such as 3 1 open 3 off, the sum of the switch is even; for example, 4 1 open 2 off 4 open, the sum of the switch is odd is to see whether there are odd factors;

#include <iostream>#include<algorithm>#include<stdio.h>#include<string.h>using namespacestd;intSolveintx) {    intCnt=0;  for(intI=1; i<=x; i++)    {        if(x%i==0) CNT++; }    if(cnt%2==0)        return 0; Else        return 1;}intMain () {intT, N; scanf ("%d", &t);  while(t--) {scanf ("%d", &N); intans=0;  for(intI=1; i<=n; i++)        {           if(Solve (i)) ans++; } printf ("%d\n", ans); }    return 0;}

The Third kind: is to see others to know, really is the world of great wonders;

The principle is: only the complete square number can have an odd number of factors, such as 3, 9, so only need to ask for the total number of squares within n;

The number of complete squares within n =sqrt (n);

#include <cstdio> #include <cmath>int main () {    int t,n;    scanf ("%d", &t);    while (t--)    {        scanf ("%d", &n);        printf ("%d\n", (int) sqrt (n));    }    return 0;}

  

HDU 1337 && POJ 1218&& zju 1350 Method Summary

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.