最近写了几道题,感觉自己懈怠了很多,vjudge的提交真的很慢,这道题不知道ac没有,先发上来再说。
You have decided that PGP encryptation is not strong enough for your email. You have decided to
supplement it by first converting your clear text letter into Pig Latin before encrypting it with PGP.
Input and Output
You are to write a program that will take in an arbitrary number of lines of text and output it in Pig
Latin. Each line of text will contain one or more words. A “word” is defined as a consecutive sequence
of letters (upper and/or lower case). Words should be converted to Pig Latin according to the following
rules (non-words should be output exactly as they appear in the input):
- Words that begin with a vowel (a, e, i, o, or u, and the capital versions of these) should just
have the string “ay” (not including the quotes) appended to it. For example, “apple” becomes
“appleay”. - Words that begin with a consonant (any letter than is not A, a, E, e, I, i, O, o, U or u) should
have the first consonant removed and appended to the end of the word, and then appending “ay”
as well. For example, “hello” becomes “ellohay”. - Do not change the case of any letter.
Sample Input
This is the input.
Sample Output
hisTay isay hetay inputay.
#include<iostream>
#include<cstring>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<bits/c++io.h>
using namespace std;
int isab(char c){
if(c>='A'&&c<='Z') return 1;
if(c>='a'&&c<='z') return 1;
else return 0;
}
int vowel(char c){
if(c=='A'||c=='E'||c=='I'||c=='O'||c=='U') return 1;
if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u') return 1;
return 0;
}
int main(int argc,char const*argv[]){
char str[1000005];
int s=0,t=0;
gets(str);
while(str[s]){
if(!isab(str[s])){
printf("%c",str[s++]);
t=s;
}
else if(isab(str[t])) t++;
else{
if(vowel(str[s])){
for(int i=s;i<t;++i){
printf("%c",str[i]);
}
}
if(!vowel(str[s])){
for(int i=s+1;i<t;++i){
printf("%c",str[i]);
}
printf("%c",str[s]);
}
printf("ay");
s=t;
}
}
printf("\n");
return 0;
}
Judging a programming contest is hard work, with demanding contestants, tedious decisions,and monotonous work. Not to mention the nutritional problems of spending 12 hours with only donuts, pizza, and soda for food. Still, it can be a lot of fun.
Software that automates the judging process is a great help, but the notorious unreliability of some contest software makes people wish that something better were available. You are part of a group trying to develop better, open source, contest management software, based on the principle of modular design.
Your component is to be used for calculating the scores of programming contest teams and determining a winner. You will be given the results from several teams and must determine the winner.
Scoring
There are two components to a team’s score. The first is the number of problems solved. The second is penalty points, which reflects the amount of time and incorrect submissions made before the problem is solved. For each problem solved correctly, penalty points are charged equal to the time at which the problem was solved plus 20 minutes for each incorrect submission. No penalty points are added for problems that are never solved.
So if a team solved problem one on their second submission at twenty minutes, they are charged 40 penalty points. If they submit problem 2 three times, but do not solve it, they are charged no penalty points. If they submit problem 3 once and solve it at 120 minutes, they are charged 120 penalty points. Their total score is two problems solved with 160 penalty points.
The winner is the team that solves the most problems. If teams tie for solving the most problems,then the winner is the team with the fewest penalty points.
Input
For the programming contest your program is judging, there are four problems. You are guaranteed that the input will not result in a tie between teams after counting penalty points.
Line 1 < nTeams >
Line 2 - n+1 < Name > < p1Sub > < p1Time > < p2Sub > < p2Time > … < p4Time >
The first element on the line is the team name, which contains no whitespace.Following that, for each of the four problems, is the number of times the team submitted a run for that problem and the time at which it was solved correctly (both integers). If a team did not solve a problem, the time will be zero. The number of submissions will be at least one if the problem was solved.
Output
The output consists of a single line listing the name of the team that won, the number of problems they solved, and their penalty points.
Sample Input
4
Stars 2 20 5 0 4 190 3 220
Rockets 5 180 1 0 2 0 3 100
Penguins 1 15 3 120 1 300 4 0
Marsupials 9 0 3 100 2 220 3 80
Sample Output
Penguins 3 475
接下来几题都AC了
#include<iostream>
#include<cstring>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<bits/c++io.h>
using namespace std;
struct teammate{
char name[100];
int sub[4];
int time[4];
int num;
int timei;
}team[10005];
int main(){
int n;
scanf("%d",&n);
for(int i=0;i<n;i++){
scanf("%s",team[i].name);
getchar();
for(int j=0;j<4;j++){
scanf("%d%d",&team[i].sub[j],&team[i].time[j]);
}
}
for(int i=0;i<n;i++){
for(int j=0;j<4;j++){
if(team[i].time[j]>0){
team[i].num++;
// printf("team[%d].timei=%d\n",i,team[i].timei);
team[i].timei+=team[i].time[j]+(team[i].sub[j]-1)*20;
}
}
}
char wname[100];
int wnum=-1,wtime=10000000;
for(int i=0;i<n;i++){
if(team[i].num>wnum||team[i].num==wnum&&team[i].timei<wtime){
strcpy(wname,team[i].name);
wnum=team[i].num;
wtime=team[i].timei;
}
}
printf("%s %d %d\n",wname,wnum,wtime);
return 0;
}
We all love recursion! Don’t we?
Consider a three-parameter recursive function w(a, b, c):
if a <= 0 or b <= 0 or c <= 0, then w(a, b, c) returns:
1
if a > 20 or b > 20 or c > 20, then w(a, b, c) returns:
w(20, 20, 20)
if a < b and b < c, then w(a, b, c) returns:
w(a, b, c-1) + w(a, b-1, c-1) - w(a, b-1, c)
otherwise it returns:
w(a-1, b, c) + w(a-1, b-1, c) + w(a-1, b, c-1) - w(a-1, b-1, c-1)
This is an easy function to implement. The problem is, if implemented directly, for moderate values of a, b and c (for example, a = 15, b = 15, c = 15), the program takes hours to run because of the massive recursion.
Input
The input for your program will be a series of integer triples, one per line, until the end-of-file flag of -1 -1 -1. Using the above technique, you are to calculate w(a, b, c) efficiently and print the result.
Output
Print the value for w(a,b,c) for each triple.
Sample Input
1 1 1
2 2 2
10 4 6
50 50 50
-1 7 18
-1 -1 -1
Sample Output
w(1, 1, 1) = 2
w(2, 2, 2) = 4
w(10, 4, 6) = 523
w(50, 50, 50) = 1048576
w(-1, 7, 18) = 1
#include<iostream>
#include<cstring>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<bits/c++io.h>
using namespace std;
int f[25][25][25];
int w(int a,int b,int c){
if(a<=0||b<=0||c<=0) return 1;
else if(a>20||b>20||c>20) return w(20,20,20);
if(f[a][b][c]) return f[a][b][c];
else if(a<b&&b<c) return f[a][b][c]=w(a,b,c-1)+w(a,b-1,c-1)-w(a,b-1,c);
else return f[a][b][c]=w(a-1, b, c) + w(a-1, b-1, c) + w(a-1, b, c-1) - w(a-1, b-1, c-1);
}
int main(int argc,char const*argv[]){
int a,b,c;
while(scanf("%d%d%d",&a,&b,&c)!=EOF){
if(a==-1&&b==-1&&c==-1) break;
printf("w(%d, %d, %d) = %d\n",a,b,c,w(a,b,c));
}
return 0;
}
In an effort to minimize the expenses for foreign affairs the countries of the world have argued as follows. It is not enough that each country maintains diplomatic relations with at most one other country, for then, since there are more than two countries in the world, some countries cannot communicate with each other through (a chain of) diplomats.
Now, let us assume that each country maintains diplomatic relations with at most two other countries. It is an unwritten diplomatic “must be” issue that every country is treated in an equal fashion. It follows that each country maintains diplomatic relations with exactly two other countries.
International topologists have proposed a structure that fits these needs. They will arrange the countries to form a circle and let each country have diplomatic relations with its left and right neighbours. In the real world, the Foreign Office is located in every country’s capital. For simplicity, let us assume that its location is given as a point in a two-dimensional plane. If you connect the Foreign Offices of the diplomatically related countries by a straight line, the result is a polygon.
It is now necessary to establish locations for bilateral diplomatic meetings. Again, for diplomatic reasons, it is necessary that both diplomats will have to travel equal distances to the location. For efficiency reasons, the travel distance should be minimized. Get ready for your task!
Input
The input contains several testcases. Each starts with the number n of countries involved. You may assume that n>=3 is an odd number. Then follow n pairs of x- and y-coordinates denoting the locations of the Foreign Offices. The coordinates of the Foreign Offices are integer numbers whose absolute value is less than 1012. The countries are arranged in the same order as they appear in the input. Additionally, the first country is a neighbour of the last country in the list.
Output
For each test case output the number of meeting locations (=n) followed by the x- and y-coordinates of the locations. The order of the meeting locations should be the same as specified by the input order. Start with the meeting locations for the first two countries up to the last two countries. Finally output the meeting location for the n-th and the first country.
Sample Input
5 10 2 18 2 22 6 14 18 10 18
3 -4 6 -2 4 -2 6
3 -8 12 4 8 6 12
Sample Output
5 14.000000 2.000000 20.000000 4.000000 18.000000 12.000000 12.000000 18.000000 10.000000 10.000000
3 -3.000000 5.000000 -2.000000 5.000000 -3.000000 6.000000
3 -2.000000 10.000000 5.000000 10.000000 -1.000000 12.000000
Hint
Note that the output can be interpreted as a polygon as well. The relationship between the sample input and output polygons is illustrated in the figure on the page of Problem 1940. To generate further sample input you may use your solution to that problem.
#include<iostream>
#include<cstring>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<bits/c++io.h>
using namespace std;
struct point{
long long x,y;
}last,now,first;
int main(int argc,char const*argv[]){
int n;
double zhongx[100005],zhongy[100005];
while(scanf("%d",&n)!=EOF){
scanf("%lld%lld",&last.x,&last.y);
first=last;
for(int i=0;i<n-1;i++){
scanf("%lld%lld",&now.x,&now.y);
zhongx[i]=(last.x+now.x)/2.0;
zhongy[i]=(last.y+now.y)/2.0;
last=now;
}
printf("%d ",n);
for(int i=0;i<n-1;i++){
printf("%.6f %.06f ",zhongx[i],zhongy[i]);
}
printf("%.6f %.6f\n",(first.x+last.x)/2.0,(first.y+last.y)/2.0);
}
return 0;
}