192 条题解
-
0片风 卡索 LV 8 @ 2006-08-25 12:34:49
纪念下~~~
编译通过...
├ 测试数据 01:答案正确... 0ms
├ 测试数据 02:答案正确... 0ms
├ 测试数据 03:答案正确... 0ms
├ 测试数据 04:答案正确... 0ms
├ 测试数据 05:答案正确... 0ms
├ 测试数据 06:答案正确... 0ms
├ 测试数据 07:答案正确... 0ms
├ 测试数据 08:答案正确... 0ms
├ 测试数据 09:答案正确... 0ms
├ 测试数据 10:答案正确... 0ms
---|---|---|---|---|---|---|---|-
Accepted 有效得分:100 有效耗时:0ms -
02006-08-24 22:23:12@
USACO原题,我老早写好的程序派上用场了
-
02006-08-17 14:57:43@
NP
-
02006-08-09 11:45:10@
其实很简单,根本不用算法就能解决!
拜托! TONYRGY 大侠的程序好像不大对劲吧!
细心一点,三遍之内绝对 AC !!! -
02006-03-07 15:09:14@
基础题,简单......
-
02006-01-23 10:56:00@
USACO上的原题,细心点就AC了
-
-12024-05-04 17:19:44@
fuck_ccf
-
-12020-07-24 14:06:34@
#include <iostream> using namespace std; int main() { int a, b; cin >> a >> b; cout << a + b << endl; }
-
-12018-03-11 19:47:10@
最最朴素的hash
第一次用了更加朴素的hash
于是无限被卡#include<iostream> #include<cstring> using namespace std; char a[16][16],c[16]; int b[12],qian[12],shou[12],xu[12],shu[12]; int main() { int i,len,np,he,j,k,u,shu1,v,po; cin>>np; for(i=1;i<=np;i++) { cin>>a[i]; len=strlen(a[i]); he=0; po=1; for(j=0;j<len;j++) { po*=27; po%=1000000007; he+=(a[i][j]-'a'+1)*po; he%=1000000007; } b[i]=he; } for(i=1;i<=np;i++) { cin>>c; len=strlen(c); he=0; po=1; for(j=0;j<len;j++) { po*=27; po%=1000000007; he+=(c[j]-'a'+1)*po; he%=1000000007; } for(j=1;j<=np;j++) { if(he==b[j]) { cin>>qian[j]>>shu1; shu[j]=shu1; memset(c,0,sizeof(c)); for(u=1;u<=shu1;u++) { memset(c,0,sizeof(c)); cin>>c; len=strlen(c); he=0; po=1; for(v=0;v<len;v++) { po*=27; po%=1000000007; he+=(c[v]-'a'+1)*po; he%=1000000007; } for(v=1;v<=np;v++) { if(b[v]==he) { he=0; shou[v]+=qian[j]/shu[j]; break; } } } memset(c,0,sizeof(c)); break; } } } for(j=1;j<=np;j++) { cout<<a[j]<<" "; if(shu[j]!=0) cout<<shou[j]-(qian[j]/shu[j]*shu[j])<<endl; else cout<<shou[j]-qian[j]<<endl; } return 0; }
-
-12017-10-14 10:28:27@
#include<iostream>
#include<cstdio>
#include<map>
#include<algorithm>
#include<cstring>
using namespace std;
int n;
struct node{
string s;
int x,y;
}a[12];
map <string,int> q;
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++){
cin>>a[i].s;
q[a[i].s]=i;
}
for(int i=1;i<=n;i++){
string s1,s2;
int m,k;
cin>>s1;
scanf("%d%d",&m,&k);
if(k==0) continue;
a[q[s1]].x+=m/k*k;
m/=k;
for(int j=1;j<=k;j++){
cin>>s2;
a[q[s2]].y+=m;
}
}
for(int i=1;i<=n;i++){
cout<<a[i].s<<" ";
printf("%d\n",a[i].y-a[i].x);
}
return 0;
} -
-12017-08-11 14:10:18@
Accepted
状态 耗时 内存占用
#1 Accepted 2ms 256.0KiB
#2 Accepted 1ms 360.0KiB
#3 Accepted 2ms 368.0KiB
#4 Accepted 3ms 356.0KiB
#5 Accepted 1ms 368.0KiB
#6 Accepted 1ms 336.0KiB
#7 Accepted 2ms 256.0KiB
#8 Accepted 2ms 256.0KiB
#9 Accepted 1ms 328.0KiB
#10 Accepted 2ms 328.0KiB#include<iostream> #include<cstring> using namespace std; int n; char name[11][16]={0}; int out[11]={0},in[11]={0}; char s[16]={0}; short ntn() { for(int i=1;i<=n;i++) if(strcmp(s,name[i])==0) return i; return 0; } int main() { cin>>n; for(int i=1;i<=n;i++) { cin>>name[i]; } for(int i=1;i<=n;i++) { int x,num; cin>>s; x=ntn(); cin>>out[x]>>num; if(num!=0) out[x]-=out[x]%num; else out[x]=0; for(int j=1;j<=num;j++) { cin>>s; in[ntn()]+=out[x]/num; } } for(int i=1;i<=n;i++) cout<<name[i]<<" "<<in[i]-out[i]<<endl; return 0; }
-
-12017-08-02 18:43:24@
var
n,i,j,k,y,z,p,q:longint;
a:array[1..100] of ansistring;
b:array[1..100] of longint;
x:ansistring;
begin
readln(n);
for i:=1 to n do
readln(a[i]);
for j:=1 to n do
begin
readln(x);
for k:=1 to n do
if a[k]=x then begin p:=k;break;end;
readln(y,z);
if z<>0 then
begin
b[p]:=b[p]+y mod z-y;
y:=y div z;
for k:=1 to z do
begin
readln(x);
for q:=1 to n do
if a[q]=x then begin p:=q;break;end;
b[p]:=b[p]+y;
end;
end;
end;
for i:=1 to n do
writeln(a[i],' ',b[i]);
end. -
-12017-07-26 17:03:57@
var
a:array[1..10]of string;
b,c:array[1..10]of longint;
s:string;
n,m,i,j,k,x,y:longint;
begin
fillchar(c,sizeof(c),0);
readln(n);
for i:=1 to n do readln(a[i]);
for i:=1 to n do
begin
readln(s);
for j:=1 to n do
if s=a[j] then begin
readln(b[j],m);y:=j;
break;end;
if m<>0 then begin
x:=(b[y] div m);
c[y]:=c[y]+(b[y] mod m);
end;
for j:=1 to m do
begin
readln(s);
for k:=1 to n do
if s=a[k] then begin c[k]:=c[k]+x; break; end;
end;
end;
for i:=1 to n do
writeln(a[i],' ',c[i]-b[i]);
end. -
-12016-09-12 22:12:21@
评测结果
编译成功
测试数据 #0: Accepted, time = 0 ms, mem = 560 KiB, score = 10
测试数据 #1: Accepted, time = 0 ms, mem = 564 KiB, score = 10
测试数据 #2: Accepted, time = 0 ms, mem = 564 KiB, score = 10
测试数据 #3: Accepted, time = 15 ms, mem = 564 KiB, score = 10
测试数据 #4: Accepted, time = 0 ms, mem = 564 KiB, score = 10
测试数据 #5: Accepted, time = 0 ms, mem = 564 KiB, score = 10
测试数据 #6: Accepted, time = 15 ms, mem = 564 KiB, score = 10
测试数据 #7: Accepted, time = 0 ms, mem = 564 KiB, score = 10
测试数据 #8: Accepted, time = 0 ms, mem = 564 KiB, score = 10
测试数据 #9: Accepted, time = 0 ms, mem = 564 KiB, score = 10
Accepted, time = 30 ms, mem = 564 KiB, score = 100
代码
c++
#include <iostream>
#include <map>
#include <string>
using namespace std;
struct people{int g,r;};
int main()
{
short np;string ns[10];map<string,people> p;
cin>>np;
for(short i=0;i<np;i++)
{
cin>>ns[i];
p[ns[i]].r=0;
}
for(short i=0;i<np;i++)
{
string name,gname;short gnum;
cin>>name;
cin>>p[name].g>>gnum;
if(gnum!=0)p[name].g-=p[name].g%gnum;
for(short i=0;i<gnum;i++)
{
cin>>gname;
p[gname].r+=p[name].g/gnum;
}
}
for(short i=0;i<np;i++)cout<<ns[i]<<" "<<p[ns[i]].r-p[ns[i]].g<<endl;
return 0;
}
-
-12016-02-18 21:29:44@
以下是我当时在USACO上写的代码,在USACO上一次AC,结果到vijos忘把重定向注释掉了,结果提交了第二次才AC……(前三行注释行我给去掉了)
c
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define mem(cur) mem[Location(cur)]
#define mem_j mem(cur).list[j]
int n;
struct{
char name[15];
int total;
int pn;
int r;
int s;
char list[20][15];
}mem[20];
char cur[15];
int Location(char* name){
int i;
for (i=1; i<=n; i++) {
if (!strcmp(name, mem[i].name)) {
return i;
}
}
return 0;
}
int main(){
// freopen("gift1.in", "r", stdin);
// freopen("gift1.out", "w", stdout);
int i,j;
scanf("%d",&n);
const int np=n;
memset(mem, 0, sizeof(mem));
for (i=1; i<=np; i++) {
scanf("%s",mem[i].name);
}
for (i=1; i<=np; i++) {
scanf("%s",cur);
scanf("%d%d",&mem(cur).total,&mem(cur).pn);
for (j=1; j<=mem(cur).pn; j++) {
scanf("%s",mem_j);
mem[Location(mem_j)].r+=mem(cur).total/mem(cur).pn;
mem(cur).s+=mem(cur).total/mem(cur).pn;
}
}
for (i=1; i<=np; i++) {
printf("%s %d\n",mem[i].name,mem[i].r-mem[i].s);
}
return 0;
}
-
-12016-02-12 22:22:49@
一次AC
Pascal AC
var n,i,j,l,k,m,t:longint; x:string;
s:array[1..10]of string;
a:array[1..10]of longint;
begin
readln(n);
for i:=1 to n do readln(s[i]);
for i:=1 to n do
begin
readln(x);
readln(k,m);
if m>0 then
begin
t:=k div m;
for l:=1 to n do
if s[l]=x then a[l]:=a[l]-m*t;
for j:=1 to m do
begin
readln(x);
for l:=1 to n do
if s[l]=x then a[l]:=a[l]+t;
end;
end;
end;
for i:=1 to n do
writeln(s[i],' ',a[i]);
end. -
-12016-01-28 12:32:40@
-
-12016-01-05 16:49:50@
测试数据 #0: RuntimeError, time = 0 ms, mem = 272 KiB, score = 0
测试数据 #1: Accepted, time = 0 ms, mem = 276 KiB, score = 10
测试数据 #2: Accepted, time = 0 ms, mem = 276 KiB, score = 10
测试数据 #3: Accepted, time = 0 ms, mem = 276 KiB, score = 10
测试数据 #4: Accepted, time = 0 ms, mem = 276 KiB, score = 10
测试数据 #5: Accepted, time = 0 ms, mem = 272 KiB, score = 10
测试数据 #6: Accepted, time = 0 ms, mem = 276 KiB, score = 10
测试数据 #7: Accepted, time = 0 ms, mem = 272 KiB, score = 10
测试数据 #8: Accepted, time = 0 ms, mem = 276 KiB, score = 10
测试数据 #9: Accepted, time = 0 ms, mem = 272 KiB, score = 10
RuntimeError, time = 0 ms, mem = 276 KiB, score = 90
代码
#include <cstdio>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string.h>
using namespace std;
struct Node
{
char name[14];
int give;
int rest;
int friends;
int friends_num[10];
};
int main()
{
freopen("gift.in","r",stdin);
freopen("gift.out","w",stdout);
int i,j,k,m,num;
cin>>num;
Node person[10];
char name[14];
for(i=0;i<num;i++)
{
cin>>person[i].name;
}
for(i=0;i<num;i++)
{
cin>>name;
for(j=0;j<num;j++)
{
if (strcmp(name,person[j].name)==0)
{
cin>>person[j].give;
cin>>person[j].friends;
break;
}}
for(m=0;m<person[j].friends;m++)
{
cin>>name;
for(k=0;k<num;k++)
{
if (strcmp(name,person[k].name)==0) {person[j].friends_num[m]=k;break;}
}
}
}
for(i=0;i<num;i++) {person[i].rest=0;}
for(i=0;i<num;i++)
{
if (person[i].give)
{
person[i].rest+=(person[i].give%person[i].friends);
for(j=0;j<person[i].friends;j++)
{
person[person[i].friends_num[j]].rest+=(person[i].give/person[i].friends);
}
}
}
for(i=0;i<num;i++)
{
cout<<person[i].name<<" "<<person[i].rest-person[i].give<<endl;
}
return 0;
}
为什么第一个错了.......... -
-12015-09-22 18:49:43@
用了下map
#include <iostream>
#include <cstdio>
#include <cstring>
#include <map>
using namespace std;int n; int mon,de,tt=0;
string names[12];
map<string,int> pp;int main()
{
ios::sync_with_stdio(false);
//freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);cin>>n ;
for (int i = 1; i <= n; ++i)
{
cin>>names[i];
pp[names[i]]=0;
}for (int i = 1; i <= n; ++i)
{
string tname;cin>>tname;
cin>>mon>>de;
pp[tname]-=mon;
if(de!=0)
{tt=mon % de;
pp[tname]=pp[tname]+tt;
}for (int j = 1; j <= de; ++j)
{
cin>>tname;
pp[tname]+=mon/de;
}
}for (int i = 1; i <= n; ++i)
cout<<names[i]<<" "<<pp[names[i]]<<endl;return 0;
} -
-12015-08-23 18:38:26@
BST+hash,装13必备(斜眼
#include <cstdio>
#include <cstring>
const int seed=131;
const int divisor=49999;
const int maxn=15;
const int maxLength=20;
struct stringList
{
char data[maxLength];
int index;
stringList* next;
stringList(char* str,int idx)
{
memcpy(data,str,sizeof(char)*maxLength);
index=idx;
next=NULL;
}
};
struct BST
{
int key;
stringList* strList;
stringList* last;
BST* leftChild;
BST* rightChild;
BST(int k,int idx,char* str)
{
key=k;
strList=new stringList(str,idx);
last=strList;
leftChild=rightChild=NULL;
}
};
int hash(char* str)
{
int result=0;
for(int i=0;i<strlen(str);i++) {
result=result*seed+str[i];
if(result>=divisor) result%=divisor;
}
return result;
}
void insert(BST* &root,int idx,char* str)
{
int h=hash(str);
if(!root) root=new BST(h,idx,str);
else if(h==root->key) {
stringList* &Nxt=root->last->next;
Nxt=new stringList(str,idx);
root->last=Nxt;
}
else if(h<root->key) insert(root->leftChild,idx,str);
else insert(root->rightChild,idx,str);
}
BST* searchNode(BST* root,int hashValue)
{
if(hashValue==root->key) return root;
else if(hashValue<root->key) return searchNode(root->leftChild,hashValue);
else return searchNode(root->rightChild,hashValue);
}
int searchString(BST* root,char* str)
{
int h=hash(str);
BST* node=searchNode(root,h);
stringList* searchStr=node->strList;
while(strcmp(str,searchStr->data)) searchStr=searchStr->next;
return searchStr->index;
}
int main()
{
//freopen("C:\data1035.txt","r",stdin);
char empty[]=" ";
BST* root=new BST(25000,-1,empty);
int N;scanf("%d",&N);
int sent[maxn],received[maxn];
char name[maxn][maxLength];
memset(sent,0,sizeof(sent));
memset(received,0,sizeof(received));
for(int i=0;i<N;i++) {
scanf("%s",name[i]);
insert(root,i,name[i]);
}
for(int i=0;i<N;i++) {
char sender[maxLength];
int money,receiverCount;
scanf("%s",sender);
int senderIdx=searchString(root,sender);
scanf("%d%d",&money,&receiverCount);
if(!receiverCount) continue;
else {
int sentToPerson=money/receiverCount;
sent[senderIdx]+=sentToPerson*receiverCount;
for(int j=0;j<receiverCount;j++) {
char receiver[maxLength];
scanf("%s",receiver);
int receiverIdx=searchString(root,receiver);
received[receiverIdx]+=sentToPerson;
}
}
}
for(int i=0;i<N;i++) {
printf("%s %d\n",name[i],received[i]-sent[i]);
}
return 0;
}