BNU Training 2015 07 27

Source: Internet
Author: User
Tags bitset cmath

"Match link": Click here~~

UVA 12435 C. Consistent verdicts"to the main idea": give you two-dimensional plane some people's coordinates, each person has a gun, ask all people at the same time after the shooting of the number of the number of shots can be heard.

"Problem Solving idea": O (n^2) Violent enumeration +unique function to re-weigh adjacent elements. I just ran 3ms,~~.

Code:

<span style= "FONT-SIZE:14PX;" >//c#ifndef _glibcxx_no_assert#include <cassert> #endif # include <cctype> #include <cerrno># Include <cfloat> #include <ciso646> #include <climits> #include <clocale> #include <cmath > #include <csetjmp> #include <csignal> #include <cstdarg> #include <cstddef> #include < cstdio> #include <cstdlib> #include <cstring> #include <ctime>//C + + #include <algorithm># Include <bitset> #include <complex> #include <deque> #include <exception> #include <fstream > #include <functional> #include <iomanip> #include <ios> #include <iosfwd> #include < iostream> #include <istream> #include <iterator> #include <limits> #include <list> #include <locale> #include <map> #include <memory> #include <new> #include <numeric> #include < ostream> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdexcept> #include <streambuf> #include <string># Include <typeinfo> #include <utility> #include <valarray> #include <vector>using namespace std; #define REP (i,j,k) for (int i= (int) j;i< (int.) k;++i) #define PER (i,j,k) for (int i= (int) j;i> (int) k;--i) #define Lowbit (a) A&-a#define Max (A, B) a>b?a:b#define Min (A, B) a>b?b:a#define mem (A, B) memset (A,b,sizeof (a)) typedef  Long long ll;typedef unsigned long long llu;typedef double db;const int n=1e6+10;const int Inf=0x3f3f3f3f;char Str[n];bool Vis[n];int dir4[4][2]= {{1,0},{0,1},{-1,0},{0,-1}};int dir8[8][2]= {{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1}    {1,-1}};int movv[5][2]= {{1,0},{0,1},{0,0},{-1,0},{0,-1}};inline LL read () {int c=0,f=1;    Char Ch=getchar (); while (ch< ' 0 ' | |        Ch> ' 9 ') {if (ch== '-') f=-1;    Ch=getchar ();        } while (ch>= ' 0 ' &&ch<= ' 9 ') {c=c*10+ch-' 0 ';    Ch=getchar (); } return C*f;} Char Mon1[n],mon2[n]; LL day1,year1; LL day2,year2;    ll Row,line,x,t,y,i,res;struct node{ll Codrx; LL Codry;}; Node Num[n];    ll Mum[n];int Main () {ll tot=1;    T=read ();        while (t--) {x=read ();        int len=0;            for (i=0; i<x; ++i) {num[i].codrx=read ();        Num[i].codry=read (); } for (int i=0, i<x; ++i) {for (int j=i+1; j<x; ++j) mum[len++]= (Num[i].codrx-num[j].        CODRX) * (NUM[I].CODRX-NUM[J].CODRX) + (num[i].codry-num[j].codry) * (Num[i].codry-num[j].codry);        } sort (Mum,mum+len);        LL res = unique (mum,mum+len)-mum;    printf ("Case%LLD:%lld\n", tot++,res+1); } return 0;} </span>

UVA 12439 G. February"Main Idea" the number of leap data between two dates: PS: The general method of judging will te, so a change of mind, to judge leap years can be used divisionCode:
<span style= "FONT-SIZE:14PX;" >//c#ifndef _glibcxx_no_assert#include <cassert> #endif # include <cctype> #include <cerrno># Include <cfloat> #include <ciso646> #include <climits> #include <clocale> #include <cmath > #include <csetjmp> #include <csignal> #include <cstdarg> #include <cstddef> #include < cstdio> #include <cstdlib> #include <cstring> #include <ctime>//C + + #include <algorithm># Include <bitset> #include <complex> #include <deque> #include <exception> #include <fstream > #include <functional> #include <iomanip> #include <ios> #include <iosfwd> #include < iostream> #include <istream> #include <iterator> #include <limits> #include <list> #include <locale> #include <map> #include <memory> #include <new> #include <numeric> #include < ostream> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdexcept> #include <streambuf> #include <string># Include <typeinfo> #include <utility> #include <valarray> #include <vector>using namespace std; #define REP (i,j,k) for (int i= (int) j;i< (int.) k;++i) #define PER (i,j,k) for (int i= (int) j;i> (int) k;--i) #define Lowbit (a) A&-a#define Max (A, B) a>b?a:b#define Min (A, B) a>b?b:a#define mem (A, B) memset (A,b,sizeof (a)) typedef Long long ll;typedef unsigned long long llu;typedef double db;const int n=1e5;const int Inf=0x3f3f3f3f;char Str[n];bool VI S[n];int dir4[4][2]= {{1,0},{0,1},{-1,0},{0,-1}};int dir8[8][2]= {{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{ 1,-1}};int movv[5][2]= {{1,0},{0,1},{0,0},{-1,0},{0,-1}};bool leap_year (int y) {if (y%4==0&&y%100!=0| |    y%400==0) return 1; return 0;}    Inline LL read () {int c=0,f=1;    Char Ch=getchar (); while (ch< ' 0 ' | |        Ch> ' 9 ') {if (ch== '-') f=-1;    Ch=getchar (); } while (ch>= ' 0 ' &&ch<= ' 9 ') {c=c*10+ch-' 0 ';    Ch=getchar (); } return c*f;} Char Mon1[n],mon2[n]; LL day1,year1; LL day2,year2;    LL Row,line,x,t,y,i,res;int Main () {scanf ("%lld", &t);        for (I=1; i<=t; ++i) {int res=0;        scanf ("%s%lld,%lld", MON1,&AMP;DAY1,&AMP;YEAR1);        scanf ("%s%lld,%lld", MON2,&AMP;DAY2,&AMP;YEAR2); if (mon1[0]== ' J ' &&mon1[1]== ' a ') | |        mon1[0]== ' F ') year1=year1;        else year1++; if (mon2[0]== ' J ' &&mon2[1]== ' a ') | |        mon2[0]== ' F ' &&day2<=28) year2--;        Res= (YEAR2/4)-((year1-1)/4);        res=res-(year2/100) + ((year1-1)/100);        res=res+ (year2/400)-((year1-1)/400);    printf ("Case%LLD:%lld\n", i,res); } return 0;} </span>


UVA 12442 J. Forwarding Emails"The main idea": The chief's long hair a letter to the tribe of people, give the tribe of people's relations, no one can only be received once and once, for the letter can be transmitted the longest number of people in the case of the first letter received the number of the person"problem-solving ideas":Online to see a more intuitive process of thinking, copied over, easy to understand: Solution Description:

DFS problem
Read This line carefully in problem description-"They all pick one other person they know to email those things To every time-exactly one, no less, no more (and never themselves)"i.e each person send email is only one . For all person have only one adjacency person. The input can not is (1 to 3, 2 to 3, 1 to 2), because for person 1 here 2 adjacency person 3 and 2. So, you can represent the this graph using one dimensional array adj[n].Do not need to the stack, you can use recursion.
Example:
4
1 2
2 1
4 3
3 2
The adjacency list, adj[1]=2, Adj[2]=1, adj[3]=2, and adj[4]=3.
Use a Boolean array visit[n]
  
 

visit[1]

VISIT[2]

visit[3]

visit[4]

False

False

False

False

At first start from 1
If Visit[1]==false then run DFS in this time count the visited node and update the visit[] Array (Set visit[i]=true here I is a visited node).  Remember dot not use the array visit[] for cycle finding you can use another a Boolean array visit2[] for that purpose. After run DFS the visit[] array is
   
  

VISIT[1]

VISIT[2]

VISIT[3]

VISIT[4]

True

True

False

False

and count_visited_node=2 (1->2)
Now 2
Visit[2]==true So, does not need to do anything.
Now 3
Visit[3]==false So, run the DFS. After, the visit[] array is
    
   

VISIT[1]

VISIT[2]

VISIT[3]

VISIT[4]

True

True

True

False

and count_visited_node=3 (3->2->1)
Now 4
Visit[4]==false So, run the DFS. After, the visit[] array is
    
   

visit[1]

VISIT[2]

visit[3]

visit[4]

True

True

True

True

and count_visited_node=4 (4->3->2->1)
For 4, the Count_visited_node is maximum. Ans is 4.
Code:
<span style= "FONT-SIZE:14PX;" > #include <stdio.h> #define MAX 50005int t,n;int Vis[max], F[max], c[max];int ans, flag;typedef long long Ll;inlin    e LL Read () {int c=0,f=1;    Char Ch=getchar (); while (ch< ' 0 ' | |    Ch> ' 9 ') {if (ch== '-') F=-1;ch=getchar ();}    while (ch>= ' 0 ' &&ch<= ' 9 ') {c=c*10+ch-' 0 '; Ch=getchar ();} return c*f;}    int dfs (int u) {int v = f[u];///2=f[1];1=f[2];2=f[3];   int r = 0;  Vis[u] = 1;    Vis[1]=1;vis[2]=1;vis[3]=1;    if (!vis[v]) R = Dfs (v) + 1;///vis[2]=1,r=0+1=1;    Vis[u] = 0;   C[u] = r;    c[1]=1,c[2]=0,c[3]=2; return r;}    int main () {int u,v;    T=read ();        for (int t=1; t<=t; t++) {n=read ();            for (int i=1; i<=n; i++) {u=read (), V=read ();            F[u] = v;            Vis[u] = 0;        C[u] =-1;        } ans =-1;            for (int i=1; i<=n; i++) {if (c[i]==-1) DFS (i);                if (c[i]>m) {m=c[i];           Flag=i; }/* printf ("Vertex%d children%d\n", i,c[i]); */} printf ("Case%d:%d\n", T,flag); } return 0;} </span>

several sets of data:

731 22 33 141 22 14 33 251 22 15 33 44 521 22 131 22 33 144 22 14 33 2101 22 33 44 55 66 77 88 99 1010 1
Case 1:1case 2:4case 3:3case 4:1case 5:1case 6:4case 7:1

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

BNU Training 2015 07 27

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.