# 刷刷刷——蒟蒻的刷水题计划(2)

1.小明A+B

[cpp]
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>

using namespace std;
int a,b,Case;
int main()
{
while(scanf("%d",&Case)!=EOF){
while(Case–){
a=a%100;
b=b%100;
printf("%d",(a+b)%100);
}
}
}
[/cpp]

poj 3069 Saruman’s Army

[cpp]
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#define maxn 1010
using namespace std;
int n,r;
int x[maxn];
void solve()
{
sort(x,x+n); //按照从左到右排序
int i=0,ans=0;
while(i<n){
int s=x[i++]; //最左端点的位置
while(i<n&&x[i]<=s+r) i++;
i–;
int t=x[i];
while(i<n&&x[i]<=t+r) i++; //找到距离t大于R的第一个点
ans++;
}
printf("%dn",ans);
}
int main()
{
while(scanf("%d %d",&r,&n)==2&&r!=-1&&n!=-1){
for(int i=0;i<n;i++)
scanf("%d",&x[i]);
solve();
}
}
[/cpp]

poj 3253 Fence Repair

[cpp]
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>
#define maxn 20010
using namespace std;
typedef long long ll;
int n,l[maxn];
ll sum,ans;
int main()
{
while(scanf("%d",&n)!=EOF){
for(int i=0;i<n;i++) {scanf("%d",&l[i]);sum+=l[i];} ans=0; while(n>1){
int mii1=0,mii2=1;
if(l[mii1]>l[mii2]) swap(mii1,mii2);
for(int i=2;i<n;i++){
if(l[i]<l[mii1]){
mii2=mii1;
mii1=i;
}
else if(l[i]<l[mii2]) {
mii2=i;
}
}
int t=l[mii1]+l[mii2];
ans+=t;
l[mii1]=t;
l[mii2]=l[n-1];
n–;
}

printf("%I64dn",ans);
}
}
[/cpp]

[cpp]
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cctype>
#include <cstring>
#include <queue>

#define maxn 20010
using namespace std;
typedef long long ll;
int n,l[maxn];
ll sum,ans;
int main()
{
while(scanf("%d",&n)!=EOF){
memset(l,0,sizeof(l));
for(int i=0;i<n;i++) scanf("%d",&l[i]);
ans=0;
priority_queue<int,vector<int>,greater<int> > que; //优先最小
for(int i=0;i<n;i++) que.push(l[i]); while(que.size()>1){
int a=que.top();
que.pop();
int b=que.top();
que.pop();
ans+=a+b;
que.push(a+b);
}
printf("%I64dn",ans);
}
}
[/cpp]

poj 2431 Expedition

[cpp]
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <queue>
#include <cstring>
#include <cctype>
#define maxn 10010
using namespace std;
struct Stop{
int pos;
int amout;
}stop[maxn];
int a[maxn];
bool cmp(Stop a,Stop b)
{
return a.pos<b.pos;
}
int n,l,p;
int main()
{
while(scanf("%d",&n)!=EOF){
memset(a,0,sizeof(a));
memset(stop,0,sizeof(stop));
bool flag=true;
for(int i=0;i<n;i++)
scanf("%d %d",&a[i],&stop[i].amout);
scanf("%d %d",&l,&p);
for(int i=0;i<n;i++){
stop[i].pos=l-a[i]; //距起点的距离
}
stop[n].pos=l;
stop[n].amout=0; //把终点视为一个加油站，现有n+1个油站
n+=1;
sort(stop,stop+n,cmp); //按照距离起点的距离排序
priority_queue<int>que;
int apos=0,tank=p,cnt=0;
for(int i=0;i<n;i++){
int d=stop[i].pos-apos;
while(tank<d){ //现有的油不够用
if(que.empty()){
flag=false;
break;
}
else{
tank+=que.top();
que.pop();
cnt++; //又加了一次油
}
}
if(!flag) break;
tank-=d;
apos=stop[i].pos; //移动到下一个加油站
que.push(stop[i].amout);

}
if(!flag) puts("-1");
else printf("%dn",cnt);
}
}
[/cpp]

uva 272

[cpp]
#include <stdio.h>

int main()
{
int c,flag=1;
while((c=getchar())!=EOF){
if(c==’"’){
if(flag)
printf("%s","");
else printf("”");
flag=!flag;
}
else printf("%c",c);
}
return 0;
}[/cpp]

uva 10082

[cpp]
#include <stdio.h>
char s[]="`1234567890-=QWERTYUIOP[]\ASDFGHJKL;’ZXCVBNM,./";
int main()
{
char c;
int i;
while((c=getchar())!=EOF){
for(i=0;i<sizeof(s)/sizeof(char)&&s[i]!=c;i++);
if(s[i]==c) printf("%c",s[i-1]);//判断是否因找到而跳出循环
else printf("%c",c);
}
return 0;
}[/cpp]

uva 401

[cpp]
#include <iostream>
#include <cctype>
#include <algorithm>
#include <cstdio>
#include <cstring>

using namespace std;
const char rev[40]="A 3 HIL JM O 2TUVWXY51SE Z 8 ";
const string msg[4]={" — is not a palindrome."," — is a regular palindrome."," — is a mirrored string."," — is a mirrored palindrome."};
char change(char ch)
{
if(isalpha(ch)) return rev[ch-‘A’];
else return rev[ch-‘0’+25];
}
int main()
{
string s;
while(cin>>s){
int len=s.length();
int huiwen=1,jingxiang=1;
for(int i=0;i<(len+1)/2;i++){
if(s[i]!=s[len-i-1]) huiwen=0;
if(change(s[i])!=s[len-1-i]) jingxiang=0;
}
if(huiwen&&jingxiang) {cout<<s<<msg[3]<<endl;cout<<endl;}
else if(huiwen&&!jingxiang) {cout<<s<<msg[1]<<endl;cout<<endl;}
else if(!huiwen&&jingxiang) {cout<<s<<msg[2]<<endl;cout<<endl;}
else {cout<<s<<msg[0]<<endl;cout<<endl;}
}
return 0;
}
[/cpp]

uva 340

[cpp]
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>
#define maxn 1010
using namespace std;
int a[maxn],b[maxn]; //a答案,b猜测
int n;
int main()
{
int cas=1;
while(scanf("%d",&n)!=EOF&&n){
printf("Game %d:n",cas++);
for(int i=0;i<n;i++) scanf("%d",&a[i]);
while(1){
int A=0,B=0;
for(int i=0;i<n;i++){
scanf("%d",&b[i]);
if(a[i]==b[i]) A++;
}
if(b[0]==0) break; //全为0跳出循环
for(int i=1;i<=9;i++){
int c1=0,c2=0; //c1统计a中某个数字的个数，c2统计b中某个数字的个数
for(int j=0;j<n;j++){
if(a[j]==i) c1++;
if(b[j]==i) c2++;
}
B+=min(c1,c2);
}

printf(" (%d,%d)n",A,B-A);
}
}
}
[/cpp]

uva 1583

[cpp]
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#define maxn 100010
using namespace std;
int a[maxn];
int x;
int main()
{
int t;
for(int m=1;m<maxn;m++){ //打表
int sum=m,tmp=m; while(tmp>0){
sum+=tmp%10;
tmp/=10;
}
if(sum<maxn&&a[sum]==0) a[sum]=m;
}
while(scanf("%d",&t)!=EOF){
while(t–){
scanf("%d",&x);
printf("%dn",a[x]);
}
}
}
[/cpp]